Yes of course.... my mistake when "washing" my original messy code

Peter Magnusson

MUSTADFORS BRUKS AB | Sågbrovägen 1 | SE66010 Dals Långed | Phone +46
(0)531-71 435 | Mobile +46 (0)76-824 96 04  | http://www.mustad.se


On Wed, Jan 12, 2011 at 15:32, Daniel Roseman <dan...@roseman.org.uk> wrote:

> On Wednesday, January 12, 2011 2:04:28 PM UTC, Peter wrote:
>>
>> If I have a couple of models like these (just an example)....
>>
>> class Parent(models.Model):
>>     name = models.CharField(max_length=100)
>>
>> class Gender(models.Model):
>>     name = models.CharField(max_length=100)
>>
>> class Child(models.Model):
>>     entity = models.ForeignKey(Entity, related_name=’children’)
>>     gender = models.ForeignKey(Gender)
>>     name = models.CharField(max_length=100)
>>
>>
>> How can i get a list of parents that _doesn't_ have a child of a
>> certain gender?
>>
>> >>> gender = Gender.objects.get(name='female')
>> >>> Parent.objects.filter(#whatever that gets parents that doesn't have a
>> child with gender=gender#)
>>
>> I'm completely lost here so please help me out.
>> If it was about getting parents with no children then
>> "children__isnull=True" should do it but now I don't know.
>> The answer is probably obvious but I'm suffering from a mental block
>> right here.
>>
>>
> Your question is a bit confusing because the Parent model doesn't seem to
> be related to anything. Should the FK to 'Entity' in Child actually be to
> Parent? Assuming yes, does this give you what you want?
>
>     Parent.objects.exclude(child__gender='female')
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> 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 django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to