On Oct 21, 2008, at 5:38 AM, timc3 wrote:
>
> So I have a model that looks like this:
>
> class GroupsOfUser(models.Model):
> name = models.CharField(_("Name"), max_length=50)
> description = models.TextField(_("Description"), blank=True,
> help_text=_("Optional"))
> slug = models.SlugField()
> group_members = models.ManyToManyField(User, verbose_name="group
> members", related_name="groupofumembers")
> group_admins = models.ManyToManyField(User, verbose_name="group
> admins", related_name="groupofuadmins")
> group_owner = models.ForeignKey(User, verbose_name="group owner",
> related_name="groupofuowner")
> date_created = models.DateTimeField(_("Creation date"),
> auto_now_add=True)
>
>
> What I have been doing is that some users are in group_members, but
> only certain users are in group_admins & in group_members. This is
> easy for me when checking whether a user has the right to see a
> GroupOfUser object, but may not be ideal.
>
> Anyway I want to return a QuerySet with all the users that are not
> group_admins, but that are in group_members, so I thought maybe
> excluding would work but I am unsure of the syntax:
>
> g = GroupsOfUser.objects.get(pk=1)
> a = g.group_admins.all()
> b = g.group_members.exclude(user_id=b)
One option would be to make "a" a list of group_admin pks, like so:
a = g.group_admins.values_list('id', flat=True)
Then you can exclude(user_id__in=a)
Is that what you were after?
E
>
>
> But of course this doesn't work when there is more than one user in a.
>
> Any help would be much appreciated.
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---