Faced such a problem, there are 3 models
class A(models.Model): ... class B(A): ... class C(B): ... print A.object.all() # Выдает модели и B и С, а надо только А
The ORM model in Django is organized in such a way that when you create a model by inheriting from another non - abstract model, the fields of the parent model are not copied into the child model, instead, the external key for the record in the parent table is created in the database in the parent table (this is done consciously from architectural considerations). Therefore, if you query all the objects for the parent table, there will be records related to the objects of the child models. Therefore, it is necessary either to filter the objects of the parent model that belong to the children, or to create abstract models from which to inherit both the parent (in this case, the model “A”) and children (“B”).