您如何在Django中扩展站点模型? [英] How do you extend the Site model in django?

查看:61
本文介绍了您如何在Django中扩展站点模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Django中扩展站点模型的最佳方法是什么?创建新模型并在Site网站上使用ForeignKey还是有另一种方法可以让我对Site模型进行子类化?

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?

我更喜欢子类化,因为相对而言我更自在,但我

I prefer subclassing, because relationally I'm more comfortable, but I'm concerned for the impact it will have with the built-in Admin.

推荐答案

我只是担心自己会对内置Admin产生影响。为此创建了一个自定义管理员。

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

基本上,当您在Django中对模型进行子类化时,它会创建指向父模型的FK并允许透明地访问父模型的字段,这与访问父类属性的方式相同在坪。
内置的管理员不会受到任何影响,但是您必须注销Sites ModelAdmin并注册自己的ModelAdmin。

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.

这篇关于您如何在Django中扩展站点模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆