Django - Polymorphic Models or one big Model?

后端 未结 2 2067
执笔经年
执笔经年 2021-02-19 08:00

I\'m currently working on a model in Django involving one model that can have a variety of different traits depending on what kind of object it is. So, let\'s say we have a mod

2条回答
  •  臣服心动
    2021-02-19 08:31

    We ended up going with a large table with a lot of usually-empty columns. Our reasoning was that (in this case) our Mammal table was all we'd be querying over, and there was no (intuitive) way to filter out by certain types of Mammals besides manually checking whether they had a "dolphin" or "elephant" object, which then threw an error if they didn't. Even looking for the type of an object returned from a query that was definitely an Elephant still returned "Mammal". It would be hard to extend any Pythonic workarounds to writing pure SQL, which one of our data guys does regularly.

提交回复
热议问题