Django admin, hide a model

后端 未结 8 1016
广开言路
广开言路 2020-11-30 23:42

At the root page of the admin site where registered models appear, I want to hide several models that are registered to the Django admin.

If I directly unregister th

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 00:27

    For Django 1.8 and above

    Since Django 1.8, ModelAdmin has got a new method called has_module_permission() which is responsible for displaying a model in admin index.

    To hide a model from admin index, just create this method in your ModelAdmin class and return False. Example:

    class MyModelAdmin(admin.ModelAdmin):
        ...
        def has_module_permission(self, request):
            return False
    

提交回复
热议问题