On Fri, Nov 23, Andrew McMurry wrote: > > I have models something like this: > > class Attribute (Model): > name = CharField(maxlength=32) > private = BooleanField(default=False) > > class Object (Model): > ... > attr = ForeignKey(Attribute, null=True, blank=True) > > now I want to exclude Objects containing a private Attribute from a > queryset: > > qs.exclude(attr_private=True) > > Unfortunately this also excludes all Objects that have no Attribute. > > Is there a way to filter a queryset that will pass Objects with no > Attribute and those whose Attribute is not private?
You need outer joins to do this in one query, and this is currently not possible. Malcolm might work on this in the queryset refactoring branch. To work around this, make two separate queries, one with qs.exclude(attr__private=True), and one with qs.filter(attr__isnull=True). Michael -- noris network AG - Deutschherrnstraße 15-19 - D-90429 Nürnberg - Tel +49-911-9352-0 - Fax +49-911-9352-100 http://www.noris.de - The IT-Outsourcing Company Vorstand: Ingo Kraupa (Vorsitzender), Joachim Astel, Hansjochen Klenk - Vorsitzender des Aufsichtsrats: Stefan Schnabel - AG Nürnberg HRB 17689 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---