I have these models:
class Model1(models.Model):
...
class Model2(models.Model):
m1 = models.OneToOneField(Model1, related_name='m2')
...
I want to get queryset of Model1 objects that have a Model2 defined. Something like this:
objs = Model1.objects.filter('m2'!=None)
but that doesn’t work.
Consider:
The argument in the brackets will be evaluated. What you’re asking of the ORM is, therefore:
What you meant was:
isnullin the Django QuerySet API Documentation