I have a list of contacts and each Contact can belong to many ContactList. What I need to do is find all contacts that does not belong to any ContactList (ie. orphan contacts).
class ContactList(models.Model):
name = models.CharField()
contacts = models.ManyToManyField(Contact)
class Contact(models.Model):
name = models.CharField()
I tried the following but it doesn't work, because contactlist_set is a reverse lookup field and not a model field.
Contact.objects.filter(contactlist_set=None)
Can some give me some direction to proceed?
Thanks
I think this should work for you: