Wednesday, January 27, 2016

Re: Reverse Foriegnkey filtering

why not filter model2 with select_related ?? (you already try to put a related_name in the foreignkey of model2?)

cheers!

Rafael E. Ferrero

2016-01-27 8:58 GMT-03:00 Jonty Needham <jontyneedham@gmail.com>:
I've found a need to do this and I'm struggling. Some info seems to indicate that django doesn't support this. How is it meant to be done?

Basically to be clear, I need to filter one queryset on a reverse foriegnkey relation to another set of objects defined by a particualr filter.

model1(Models.model):
    stuff = charfield

model2(Models.model):
    cow = Foreignkey(model1)
    country = charfield


Problem: filter set of model1's by a particular country that's related to model1 through model2

--
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/CANOQRbw40C9NTiwLc_c3cT9BWLj_nDKnk76KSb1U57w0VXq_ag%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
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/CAJJc_8UETZdT5tmdKzrJ%3DCWXnZH7jfss9tVsPkGriLjTXXKkgg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment