How can I define a polymorphic relation between models in Django?

前端 未结 5 1965
夕颜
夕颜 2021-02-05 14:25

I am working on a Django application which contains an Offer model. An Offer instance contains the pricing conditions and points to a product definiti

5条回答
  •  隐瞒了意图╮
    2021-02-05 14:50

    ContentTypes is the right approach. This is because the ForignKey can only point to one type of table so you need to pass through the an intermediate table and do your split depending on the different type.

    So model inheritance for the class hierarchy, but ContentType for the foreign keys.

提交回复
热议问题