Is it possible to access a specific record of a QuerySet based on a value in one of its fields — from within the template?
Let’s say I have the following models:
Parent:
someField
Child:
parentFK = ForeignKey(Parent)
bar = CharField
If Parent has many children, and I pass the QuerySet of Parent.objects.all() to my template, is it possible to access something like: Parent.someField.bar where foo=4?
In otherwords, access and display the field bar for the record where foo holds the value 4? I only want to pass the Parent QuerySet to the template.
Thanks!
You can do it using custom template tag.
P.S. Is your model description correct? If you have Parent with many children is it ok, that parent contains a link to child, not vice-versa?