search

Home  >  Q&A  >  body text

python - django admin如何显示多个模块?

如何在admin后台显示的时候,显示成多个模块?

目前我的代码

class LevelAdmin(admin.ModelAdmin):
    list_display = ['level1', 'level2']

class BaseUrlAdmin(admin.ModelAdmin):
    list_display = ['package_url', 'package_url_desc', "package_url_tag"]
    
admin.site.register(LevelForUrl, LevelAdmin)
admin.site.register(BaseUrl, BaseUrlAdmin)

如上图所示,admin.py里如何写才能达到以上效果?

大家讲道理大家讲道理2892 days ago257

reply all(2)I'll reply

  • PHPz

    PHPz2017-04-17 18:01:50

    I was too busy the past few days, so I finally researched it. It turns out it is very simple. Please forgive my ignorance. . .
    Answer it yourself, the idea is:

    • Create a new app, epython manage.py startapp proname;

    • Then build the Model in the models of this app;

    • Register this model in admin.py in the newly created app;

    • Sync python manage.py makemigrations \ python manage.py migrate

    • Just restart your service

    The effect is as follows:

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 18:01:50

    You may need to implement an AdminSite yourself, and then register(.......,site=)

    reply
    0
  • Cancelreply