是否可以将不同应用程序的模型分组到 1 个管理块中?
例如我的结构是
project/
review/
models.py - class Review(models.Model):
followers/
models.py - class Followers(models.Model):
admin.py
In followers/admin.py
, 我打电话
admin.site.register(Followers)
admin.site.register(Review)
这是为了将它们分组到 1 个管理块中,以便管理员轻松查找内容。
我试过了,但是Review
模型没有出现在里面Followers
管理块,我找不到有关此的文档。
Django Admin 将模型按其应用程序分组到管理块,该应用程序定义为Model._meta.app_label
。从而注册Review
in followers/admin.py
仍然可以将其发送到应用程序review
.
所以做一个代理模型 https://docs.djangoproject.com/en/1.4/topics/db/models/#proxy-models of Review
并将其放入“评论”应用程序中
class ProxyReview(Review):
class Meta:
proxy = True
# If you're define ProxyReview inside review/models.py,
# its app_label is set to 'review' automatically.
# Or else comment out following line to specify it explicitly
# app_label = 'review'
# set following lines to display ProxyReview as Review
# verbose_name = Review._meta.verbose_name
# verbose_name_plural = Review._meta.verbose_name_plural
# in admin.py
admin.site.register(ProxyReview)
另外,你可以把Followers
and Review
到同一个应用程序或设置相同app_label
对于他们来说。
自定义管理视图或使用第 3 部分仪表板may也达到目的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)