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

前端 未结 7 1849
自闭症患者
自闭症患者 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:39

    At its root, this is part of the mismatch between objects and relational databases. The ORM does a great job in abstracting out the differences, but sometimes you just come up against them anyway.

    Basically, you have to choose between abstract inheritance, in which case there is no database relationship between the two classes, or multi-table inheritance, which keeps the database relationship at a cost of efficiency (an extra database join) for each query.

提交回复
热议问题