例如代替:app/admin.py class PersonAdmin(admin.ModelAdmin): [...] class CarAdmin(admin.ModelAdmin) [...]我会app/admin/personadmin.py class PersonAdmin(admin.ModelAdmin): [...]app/admin/caradmin.py class CarAdmin(admin.ModelAdmin) [...]我想在不更改Django代码的情况下执行此操作.这只是为了概述,我知道它并没有为网站的运作打开新的可能性.非常感谢您的帮助!解决方案您是否尝试过在admin目录下创建__init__.py文件? 内容如下:from personadmin import PersonAdminfrom caradmin import CarAdmin只需按照您链接的说明进行操作,但将模型"替换为管理员".试试看,看看是否可行.如果没有的话,我会感到惊讶.In Django, is it possible to place forms for models in the admin interface into different files per app? The same as can be done for model files.E.g. instead of:app/admin.py class PersonAdmin(admin.ModelAdmin): [...] class CarAdmin(admin.ModelAdmin) [...]I'd haveapp/admin/personadmin.py class PersonAdmin(admin.ModelAdmin): [...]app/admin/caradmin.py class CarAdmin(admin.ModelAdmin) [...]I would like to do this without changing Django code.It's just for overview, I know it doesn't open up new possibilies for the functioning of the site.Any help is much appreciated! 解决方案 Have you tried creating an __init__.py file under the admin directory? The contents would look like:from personadmin import PersonAdminfrom caradmin import CarAdminJust follow the instructions you linked to, but replace "models" with "admin". Try it and see if it works. I'd be surprised if it doesn't. 这篇关于将Django管理表单放置在不同的文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-16 05:58