On Aug 18, 8:28 pm, Chris McComas <mccomas.ch...@gmail.com> wrote:
> I have a model that has a FK to django.contrib.auth.models Group. I
> run a query that gets all the groups that a user is a member of:
>
> groups = Group.objects.filter(user=request.user)
>
> Then I want to run a query for that model that gets and entries in
> that model where the group FK is one of the groups in the groups
> query. So like:
>
> course = Course.objects.filter(group=groups)
>
> How can I do this?

Like this:

course = Course.objects.filter(group__in=groups)

However, you can do the whole thing in one query:

course = Course.objects.filter(group__user=request.user)

--
DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to