How to query abstract-class-based objects in Django?

前端 未结 7 1860
自闭症患者
自闭症患者 2020-12-13 17:11

Let\'s say I have an abstract base class that looks like this:

class StellarObject(BaseModel):
  title = models.CharField(max_length=255)
  description = mod         


        
7条回答
  •  一个人的身影
    2020-12-13 17:46

    You can't query abstract base classes. For multi-table inheritance you can use django-model-utils and it's InheritanceManager, which extends standard QuerySet with select_subclasses() method, which does right that you need: it left-joins all inherited tables and returns appropriate type instance for each row.

提交回复
热议问题