I have a model with a FK on User table:
    from django.contrib.auth.models import User

    class Ticket(models.Model):
        assigned_to = models.ForeignKey(User, null=True, blank=True)
        ...

Then I have these two querysets:
    >>> q1 = Ticket.objects.filter(assigned_to__isnull=True)
    >>> q2 = Ticket.objects.exclude(assigned_to__isnull=False)

I thought they shoud generate the same SQL query as they are
conceptually the same thing.

But if I print their query I got:
    >>> print q1.query
    SELECT ...
    FROM "ticket_ticket"
    LEFT OUTER JOIN "auth_user" ON ("ticket_ticket"."assigned_id" =
"auth_user"."id")
    WHERE "auth_user"."id" IS NULL

    >>> print q2.query
    SELECT ...
    FROM "ticket_ticket"
    WHERE NOT ("ticket_ticket"."assigned_id" IS NOT NULL)

The exclude version is much more efficient.

Is this by design?

Ciao.
Marco.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to