I have a Django model like:
class Category(models.Model):
status=models.CharField(max_length=16)
machineName=models.CharField(max_length=50)
readableName=models.CharField(max_length=100)
description=models.CharField(max_length=1024)
parents=models.ManyToManyField('self')
Where each category may exist in many parents. Some categories have no parents, they are the "root" categories. In plain SQL I could find them by:
SELECT "readableName"
FROM foo_category AS c
LEFT JOIN foo_category_parents AS cp ON (c.id=cp.from_category_id)
WHERE cp.to_category_id IS NULL;
And indeed, this works well. How do I find the "list of categories with no parents" with a Django-y call? I tried:
# Says "Cannot resolve keyword 'is_null' into field."
Category.objects.filter(parents__is_null=True)
# Says "Join on field 'id' not permitted."
Category.objects.filter(parents__pk_null=True)
But as noted, neither work.