description:
i know how access foreignkey's field within template code.
given sample models.py code:
class publisher(models.model): name = models.charfield(max_length=30) address = models.charfield(max_length=50) class book(models.model): title = models.charfield(max_length=100) publisher = models.foreignkey(publisher)
and sample forms.py code:
class bookform(modelform): class meta: model = book fields = ['title', 'publisher']
and sample views.py code:
def sample(request): bf = bookform(request.post) return render(request, 'sample.html', {'bookform': bf})
question:
what line(s) of code needed correctly access value: publisher.name within template code using 'bookform'?
i have been able use {{ bookform.instance.publisher.name }}
display foreign field values. works display current instance.
Comments
Post a Comment