29👍
✅
A.objects.filter(b__c__isnull=False)
results a sql w/ same result:
SELECT DISTINCT a.* FROM a
INNER JOIN b ON (a.id = b.a_id)
INNER JOIN c ON (b.id=c.b_id)
WHERE c.id IS NOT NULL;
P.S. Why do you use IntegerField
instead of AutoField
for ids?
👤okm
Source:stackexchange.com