I have two models, A and B, and B is ForienKey relationship to A.
I want to check each object in queryset and if it has certain fields then I want to display it in template.
Below is my template example:
{% for a in a_qs %}
<tr>
<th>{{ a.b_set.first.a_field }}</th>
<th>{{ a.b_set.first.another_field }}</th>
{% endfor %}
They work fine, but I want to apply something like get method in queryset. Below is what I want to achieve:
{% for a in a_qs %}
<tr>
<th>{{ a.b_set.get(a_field_in_B='hello').a_field }}</th>
<th>{{ a.b_set.get(a_field_in_B='hello').another_field }}</th>
{% endfor %}
I understand that something above is not possible and I want to give some change to my views or models, but I don't know where to start.
Below is something like my views.py snippet:
a_qs = A.objects.all()
a_obj = a.b_set.get(a_field='something') # a is not defined yet. I want every a in a_qs to be checked
Thanks for your advice in advance.