views:

46

answers:

1

Hay,

I have a Model which looks like this

class Person(models.Model):
    name = models.CharField(blank=False, max_length=100)
    friends = models.ManyToManyField('self', blank=True, null=True)

How would i filter out a Person how has friends?

I tried

people_with_friends = Person.objects.filter(friends=True)

but had no luck.

Anyone lend a helping hand?

Thanks

+3  A: 

What about this?

people_with_friends = Person.objects.exclude(friends=None)
msanders
This works, but i have no idea why the original solution doesn't! Thanks anyway!
dotty
I think the original solution doesn't work because the value of 'friends' (when the person has friends) is a ManyRelatedManager object and you are testing for the value to equal True.
msanders