1👍
✅
It’s not clear to me what you’re trying to do from your question and your view code confuses things further as you assign the result of Plaque.objects.all()
to two different variables and then put them together. The ForeignKey
objects on the Plaque
model will all be available in the queryset. You can use select_related
to make sure you pull them all back efficiently, like so:
plaques = Plaque.objects.select_related("veteran").all()
for p in plaques:
print p.veteran
N.B., the .all()
isn’t strictly necessary but I wanted to make it clear I was using the same query as you and simply adding to it.
👤Tom
0👍
You should be able to use the select_related method.
queryset_list = Plaque.objects.select_related('Veteran').all().order_by('first_name')
The detail is provided in the Django documentation.
- How to run Django project locally for Heroku
- Prevent Django from logout through url before hitting enter
- Get_queryset() in MonthArchiveView returns all objects instead objects created only in requested month
- Django site, getting error __init__() missing 1 required positional argument: 'request' when calling a view
Source:stackexchange.com