Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django - query filter on manytomany is empty

In Django is there a way to filter on a manytomany field being empty or null.

class TestModel(models.Model):     name = models.CharField(_('set name'), max_length=200)     manytomany = models.ManyToManyField('AnotherModel', blank=True, null=True)  print TestModel.objects.filter(manytomany__is_null=True) 
like image 565
John Avatar asked Nov 15 '10 12:11

John


1 Answers

print TestModel.objects.filter(manytomany=None) 
like image 71
Bernhard Vallant Avatar answered Oct 06 '22 01:10

Bernhard Vallant