[Answered ]-Can a parent class check if child class has such field?

2👍

You can reference subclass properties by using the subclass as a field name:

Parent.objects.filter(child__isnull=True)

yields all bare Parent instances (that are not children).

This gets slightly unwieldy when you have multiple derived classes, though.

Obviously, you can also query for child fields via the parent class this way:

Parent.objects.filter(child__has_that=True)

yields instances of Parent that are also Children with has_that set to True.

👤dhke

Leave a comment