On Fri, Apr 17, 2009 at 3:18 PM, Daniel Roseman
<roseman.dan...@googlemail.com> wrote:
>
> On Apr 17, 1:23 pm, Bastien <bastien.roche...@gmail.com> wrote:
>> Hi,
>>
>> I'm trying to retrieve a list of users belonging  to a given group but
>> don't understand how to do it. It must be a sort of many to many query
>> but I can't get it to work.
>>
>> I would like to do something like this:
>>
>> basic_users_list = User.objects.filter(groups__in=Group.objects.get
>> (name='basic'))
>>
>> but django tells me that:
>>
>> 'Group' object is not iterable
>>
>> If there is another way to do some actions on a given group then I
>> would be as happy.
>>
>> thanks for your guidance.
>
> Does this not work?
> basic_users_list = User.objects.filter(
>    groups=Group.objects.get(name='basic'))
>

You're hitting the database twice which seems unnecessary given that
you don't do anything with the group object.

You could simply use the following piece of code and be done with it:

basic_users_list = User.objects.filter(groups__name='basic')

Or have I missed something?

--~--~---------~--~----~------------~-------~--~----~
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