Django ORM fastest query to join two models and get a list of paired tuples
Here is how my models.py
look like:
Now in my views.py
I want to have a function like:
what I want as output of index function is a list of tuple like [(bar_1, hat_1),(bar_2, hat_2), ...]
where for each hat_i
we have hat_i.bar == bar_i
and if there is no Hat object associated with a bar_i
I want it to be paired with None.
What's the fastest way that I can build such list in Django?
Try This
finally, final_list should have required contents.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.