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

前端 未结 5 1985
夕颜
夕颜 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 15:00

    If you only need to point to "any product," not any model, then the solution is to have a Product model that all products inherit from (i.e. Television and Camcorder are both subclasses of Product), and give your Offer model a ForeignKey to Product.

提交回复
热议问题