Consider the model schema:
class A(models.Model):
id = models.IntegerField(...)
...
class B(models.Model):
parent = models.OneToOneField(A, primary_key=True)
And further assume that there are more rows of A than B (e.g. not all As have details). How would I generate a query that gives me only As which have associated Bs?
I’ve tried A.objects.filter(b__isnull=False) which doesn’t seem to work, it still returns all rows in A.
I just tried this, and it works for me:
or, a somewhat hackier version that relies on the (usually) integer non negative nature of primary keys
Now, I have a related_name, so if those don’t work for you, try adding related_name.