views:

362

answers:

3

Hello 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 ?

+1  A: 

Ugly solution: override admin index template i.e. copy index.html from django to your /admin/index.html and add something like this:

{% for for model in app.models %}
    {% ifnotequal model.name "NameOfModelToHide" %}
    ...
alex vasi
+2  A: 

Got the same problem, here what I came up with.

Like in previous solution - copy index.html from django to your /admin/index.html and modify it like this:

{% for model in app.models %}
    {% if not model.perms.list_hide %}
    <tr>
    ...
    </tr>
    {% endif %}
{% endfor %}

And create ModelAdmin subclass:

class HiddenModelAdmin(admin.ModelAdmin):
    def get_model_perms(self, *args, **kwargs):
        perms = admin.ModelAdmin.get_model_perms(self, *args, **kwargs)
        perms['list_hide'] = True
        return perms

Now any model registered with HiddenModelAdmin subclass won't show up in admin list, but will be available via "plus" symbol in detail:

class MyModelAdmin(HiddenModelAdmin):
    ...

admin.site.register(MyModel, MyModelAdmin)
x0nix
thanks alot for the answer!
Hellnar
A: 

Django 1.2 has new if-statements, meaning that the desired feature could be obtained only by overwriting admin/index.html

{% if model.name not in "Name of hidden model; Name of other hidden model" %}
    ...
{% endif %}

This is a bad solution, because it doesn't care about multi-language admins. You could of course add the names of models in all of the supported languages. It's a good solution because it doesn't overwrite more than one aspect of core Django functions.

But before changing anything, I think people should think about this...

Essentially the problem is related to having models that one does not wish to use for more than adding an option to a drop-down once in a while. It could effectively be worked around by creating a set of permissions for "not so advanced" users that panic when there are too many models. In case changes in the particular models are required, one can simply log in with the "advanced account".

benjaoming