假设我有一组模型必须在管理员中与另一组分开(可视).
现在它们是字母的,这使它们混乱.
我想用这种方式组织它们:
我似乎无法找到有关如何执行此操作的文档.这甚至可能吗?
Jar*_*rno 17
我不认为拆分你的业务逻辑,即你的应用程序,当你想要实现的是某种标记是正确的方式.相反,我找到了Python包django-modeladmin-reorder,可以让你轻松实现这一目标.您可以将其标记应用程序和重新排序模型的功能组合到管理员中的一个应用程序的组模型中.按照安装说明操作后,将类似的内容添加到您的settings.py
ADMIN_REORDER = (
# First group
{'app': 'myapp', 'label': 'Group1',
'models': ('myapp.Model_1',
'myapp.Model_4',)
},
# Second group: same app, but different label
{'app': 'myapp', 'label': 'Group2',
'models': ('myapp.Model_2',
'myapp.Model_3',)
},)
Run Code Online (Sandbox Code Playgroud)
Edw*_*ndo -6
您需要创建两个应用程序。第一个应用 == 组 1。第二个应用 == 组 2。
然后,您需要在新应用程序中创建代理模型。像这样的东西。
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)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7039 次 |
最近记录: |