简体   繁体   English

Django - 拆分 admin.py

[英]Django - Splitting admin.py

I tried to split admin.py with the following steps but failed.我尝试使用以下步骤拆分 admin.py 但失败了。
- Remove admin.py - 删除 admin.py
- Create folder named "admin" - 创建名为“admin”的文件夹
- Create files in folder "admin". - 在文件夹“admin”中创建文件。 modela.py, modelb.py模型a.py, 模型b.py
- Create "_ init _.py" and leave it empty - 创建“_ init _.py”并将其留空
- In the "modela.py" file - 在“modela.py”文件中

from django.contrib import admin
from myapp.models import *

@admin.register(ModelA)
class ModelAAdmin(admin.ModelAdmin):
    class Meta:
        model = ModelA

But the model is not showing in my admin site.但是模型没有显示在我的管理站点中。 What's wrong with the steps above or I missed anything?上面的步骤有什么问题,或者我错过了什么?

Firstly, the file is called __init__.py , with two underscores each side.首先,该文件名为__init__.py ,每边有两个下划线。 Secondly, leaving it empty won't do anything at all;其次,让它空着不会做任何事情; you would need to import your admin classes into that file.您需要将管理类导入该文件。

In __init__.py you should import the admin files you want to use.__init__.py您应该导入要使用的管理文件

from . import adminA.py
from . import adminB.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM