Friday, February 23, 2018

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

If you want to have Articles then get Article.objects.filter(section=xy).oder_by('section__order')

Am Donnerstag, 22. Februar 2018 20:47:31 UTC+1 schrieb James Farris:

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.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/57baf37b-601f-4bb3-b7f2-b66daac6147c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment