Re: Query API: get all users without a group

2008-12-03 Thread Thomas Guettler
Filip Wasilewski schrieb: > On 2 Gru, 16:45, Thomas Guettler <[EMAIL PROTECTED]> wrote: > >> Hi, >> >> I want to get all objects where the corresponding many-to-many field is >> empty. >> >> Example: get all users without a group >> > [...] > > The preferred solution is using the

Re: Query API: get all users without a group

2008-12-02 Thread [EMAIL PROTECTED]
You could do User.objects.exclude(groups__in=Group.objects.all ().query) which will actually generate a subquery. Alex On Dec 2, 10:45 am, Thomas Guettler <[EMAIL PROTECTED]> wrote: > Hi, > > I want to get all objects where the corresponding many-to-many field is > empty. > > Example:  get all

Re: Query API: get all users without a group

2008-12-02 Thread Filip Wasilewski
On 2 Gru, 16:45, Thomas Guettler <[EMAIL PROTECTED]> wrote: > Hi, > > I want to get all objects where the corresponding many-to-many field is > empty. > > Example:  get all users without a group [...] The preferred solution is using the `isnull` filter: User.objects.filter(groups__isnull=True)

Query API: get all users without a group

2008-12-02 Thread Thomas Guettler
Hi, I want to get all objects where the corresponding many-to-many field is empty. Example: get all users without a group My solution: User.objects.exclude(groups__in=Group.objects.all()) I think this is not optimal, since Group.objects.all() gets evaluated. Resulting SQL: SELECT