I have 2 models:
class Friend(models.Model):
person1 = models.ForeignKey("Person", related_name="friend1")
person2 = models.ForeignKey("Person", related_name="friend2")
created = models.DateTimeField(auto_now=True, auto_now_add=True, editable=False)
class Person(models.Model):
firstname = models.CharField(max_length=100)
surname = models.CharField(max_length=100)
created = models.DateTimeField(auto_now=True, auto_now_add=True, editable=False)
I want a list of Person
objects which do not have any entries in the Friend
object. e.g.
no_friends = Person.objects.filter(????)
but I'm not sure what the filter should be.
Try to use the related manager.
no_friends = Person.objects.filter(friend1=None,friend2=None)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With