Getting complex query set with a many to many relationship in django

15 views
Skip to first unread message

James Farris

unread,
Feb 22, 2018, 2:47:31 PM2/22/18
to Django users

I am trying to get all article objects that are part of a section in an edition that is in an issue. I am stumped, even after looking at the documentation for django 2.x

I can get all editions with all of their sections that are part of an issue, but I cannot figure out how to get articles that are related to a section per edition.


Sample code is here:
https://codeshare.io/5vXbAD

Please note I have a many to many pass through table that has extra fields I am trying to get.  Specifically the "order" field.
Here is a screenshot for proof of concept
https://pasteboard.co/H8N2zTt.png

If you are able to get all articles returned from the loop in the code linked above, I will be eternally grateful :)

results would be passed to a template.

Andy

unread,
Feb 23, 2018, 6:58:46 AM2/23/18
to Django users
If you want to have Articles then get Article.objects.filter(section=xy).oder_by('section__order')
Reply all
Reply to author
Forward
0 new messages