Ram-
I believe that
User.objects.filter(related__name__starts_with='A')
would get you what you're looking for, per the example at <http://
www.djangoproject.com/documentation/models/many_to_many/> starting
with block "# We can perform kwarg queries across m2m relationships".
On Jan 28, 11:19 am, "Ramashish Baranwal" <[EMAIL PROTECTED]>
wrote:
> Hi,
>
> I would like to restrict a QuerySet based on its ManyToManyField. In
> particular, based on what the ManyToManyField contains. Consider this
> trivial and a bit non-sense example-
>
> class User:
> name = models.CharField(maxlength=24)
> related = models.ManyToManyField('self', symmetric=False)
>
> I want to get Users who are related to other users whose names start
> with 'A'. e.g.
>
> pplA = User.objects.filter(name__starts_with='A')
>
> # The below doesn't result in what I expect.
> #relatedA = User.objects.filter(related__in=ppl)
>
> I am looking for a clause that can help me accomplish this but ain't
> able to find in docs.
>
> Thanks in advance,
> -Ram
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---