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
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
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)
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
4 matches
Mail list logo