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
I had lots of model admins to register and hide, if you want a more DRY solution, this worked for me (Django 1.10, Python 3.5)
# admin.py
def register_hidden_models(*model_names):
for m in model_names:
ma = type(
str(m)+'Admin',
(admin.ModelAdmin,),
{
'get_model_perms': lambda self, request: {}
})
admin.site.register(m, ma)
register_hidden_models(MyModel1, MyModel2, MyModel3)
I guess you could roll it into a utility class if you want to re-use it across apps.