Wednesday, December 23, 2015

Re: Fitering on manytomany field whose results are contained within another set...

Thanks :-) Should have guessed it was that easy!

On Wed, Dec 23, 2015 at 12:44 PM, Vijay Khemlani <vkhemlan@gmail.com> wrote:
You should be able to query it as a ForeignKey

Jobs.objects.filter(names__is_a_problem=True).distinct()

(distinct to prevent repeated jobs with more than one worker problem)


On Wed, Dec 23, 2015 at 9:31 AM, Jonty Needham <jontyneedham@gmail.com> wrote:
I have a model of the form:

class Jobs(models.Model):
        names  = models.ManyToManyField(Workers)

class Workers(modesl.Model):
     is_a_problem = True


And I want the set of jobs that are done by workers who are a problem.

Something like

Jobs.objects.filter(names__is_contained_in=Workers.objects.filter(is_a_problem=True))

Obviously is_contained_in is not a valid lookup, so I would like to know how to do this please.

Thanks
Jonty

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

No comments:

Post a Comment