Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django admin, hide a model

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 those, I am not able to add new records as the add new symbol "+" dissapears.

How can this be done ?

like image 413
Hellnar Avatar asked Mar 12 '10 09:03

Hellnar


People also ask

How do I hide fields in Django admin?

In Django 1.8 exclude = ('fieldname',) does works with admin. ModelAdmin so one does not have to inherit from InlineModelAdmin anymore. Also works in Django 1.6.

Is it possible to create a custom admin view without a model behind it?

The most straightforward answer is "no". As the Django Book says, the admin is for "Trusted users editing structured content," in this case the structured content being models arranged in hierarchies and configured through settings.py.

What is Django admin interface?

Django provides a default admin interface which can be used to perform create, read, update and delete operations on the model directly. It reads set of data that explain and gives information about data from the model, to provide an instant interface where the user can adjust contents of the application .


1 Answers

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) 
like image 52
shaunsephton Avatar answered Sep 18 '22 07:09

shaunsephton