简体   繁体   English

在开发中的Django管理面板中显示所有模型

[英]Showing all models in Django admin panel in development

When I am developing I constantly need to access data from the admin panel but I do not wish to add all models in admin.py since I do not want them to be accessed in production. 在开发时,我经常需要从管理面板访问数据,但是我不希望在admin.py中添加所有模型,因为我不想在生产环境中访问它们。

Is there a way to show all models in the admin panel in the development environment and hide (part of) them in production automatically? 有没有一种方法可以在开发环境的管理面板中显示所有模型,并在生产中自动隐藏(部分)模型?

I think that would be as simple as this: 我认为这就是这么简单:

# my_app/admin.py

from django.contrib import admin
from django.conf import settings

from .models import MyModel, AnotherModel

class MyModelAdmin(admin.ModelAdmin):
    pass

class AnotherModelAdmin(admin.ModelAdmin):
    pass

# conditional registration of models
if settings.DEBUG:
    admin.register(MyModel, MyModelAdmin)
    admin.register(AnotherModel, AnotherModelAdmin)

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

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