Reputation: 6355
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?
Upvotes: 4
Views: 1444
Reputation: 6355
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
Upvotes: 4
Reputation: 5854
You can try this
this will hide the model from the index
class YourModel(admin.ModelAdmin):
def get_model_perms(self, request):
return {} # return empty
admin.site.register(YourModel, YourModelAdmin)
more about Django admin https://docs.djangoproject.com/en/3.1/ref/contrib/admin/
Upvotes: 3