pythondjangodjango-admindjango-modeladmin

Django Admin exclude model from index and app page


I want to hide some models from admin index page and app page. For example, these that I have visible in inlines as related objects.
One more point, I want to keep the ability to work with change_view and add_view, but not list_view of that model.

Tried to find any hints in admin/templates/admin/*.html files, but haven't found anything helpful.

Is it possible without "hacks", monkey-patching and external libraries?


Solution

  • As Django documentation tells:

    ModelAdmin.has_module_permission(request)
    Should return True if displaying the module on the admin index page and accessing the module’s index page is permitted, False otherwise. Uses User.has_module_perms() by default. Overriding it does not restrict access to the view, add, change, or delete views.

    To avoid removal all permissions (like with get_model_perms()) you can redefine has_module_permission() method to always return False.

    @admin.register(SomeModel)
    class SomeModelAdmin(admin.ModelAdmin):
    
        def has_module_permission(self, request):
            return False