On Mar 23, 2011, at 12:19 PM, Julien Castets wrote: > Hello, > > from django.contrib.auth.models import User > > class Team(models.Model): > users = models.ManyToManyField(User) > > > I would like to retrieve every User in my database who does not belong > to a team.
Left outer join is your friend .... User.objects.filter(team__users__isnull = True) > I'm facing to this problem for several hours, and I found a *very* > crappy solution : > > def _get_all_users_in_teams(): > for team in Team.objects.all(): > for user in team.users.all(): > yield user.pk > > CHOICES = User.objects.all().exclude(pk__in=[id for id in > _get_all_users_in_teams()]) > > Is there something better? > I'm on django 1.2.4 > > Regards, > -- > J. > > -- > 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. > -- 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.

