[Django]-How to queryset inheritance model django?

4👍

You can query with:

Final.objects.filter(parent__child1__att1='abc')

In Django model inheritance (of non-abstract models) is achieved by adding an implicit OneToOneField in the child model(s). We can thus use that relation by querying in reverse.

This will thus create a query that looks like:

SELECT final.*
FROM final
INNER JOIN parent ON final.parent_id = parent.id
INNER JOIN child1 ON parent.id = child1.parent_ptr_id
WHERE child1.att1 = 'abc'

Leave a comment