How do you extend the Site model in django?

后端 未结 5 1315
情书的邮戳
情书的邮戳 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:10

    If you only want to change behaviour of the object, but not add any new fields, you should consider using a "proxy model" (new in Django 1.1). You can add extra Python methods to existing models, and more:

    This is what proxy model inheritance is for: creating a proxy for the original model. You can create, delete and update instances of the proxy model and all the data will be saved as if you were using the original (non-proxied) model. The difference is that you can change things like the default model ordering or the default manager in the proxy, without having to alter the original.

    Read more in the documentation.

提交回复
热议问题