Django admin, hide a model

后端 未结 8 1012
广开言路
广开言路 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:32

    Based on x0nix's answer I did some experiments. It seems like returning an empty dict from get_model_perms excludes the model from index.html, whilst still allowing you to edit instances directly.

    class MyModelAdmin(admin.ModelAdmin):
        def get_model_perms(self, request):
            """
            Return empty perms dict thus hiding the model from admin index.
            """
            return {}
    
    admin.site.register(MyModel, MyModelAdmin)
    

提交回复
热议问题