dotty
dotty

Reputation: 41533

django manytomany filter question

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

Upvotes: 2

Views: 1397

Answers (1)

msanders
msanders

Reputation: 5919

What about this?

people_with_friends = Person.objects.exclude(friends=None)

Upvotes: 7

Related Questions