How do you extend the Site model in django?

后端 未结 5 1317
情书的邮戳
情书的邮戳 2021-02-07 23:40

What is the best approach to extending the Site model in django? Creating a new model and ForeignKey the Site or there another approach that allows me to subclass the Site model

5条回答
  •  日久生厌
    2021-02-08 00:17

    I just used my own subclass of Site and created a custom admin for it.

    Basically, when you subclass a model in django it creates FK pointing to parent model and allows to access parent model's fields transparently- the same way you'd access parent class attributes in pyhon. Built in admin won't suffer in any way, but you'll have to un-register Sites ModelAdmin and register your own ModelAdmin.

提交回复
热议问题