Force a model to appear on admin's index page depending on the request

9 views
Skip to first unread message

Olivier Dalang

unread,
Apr 13, 2016, 12:26:03 PM4/13/16
to django...@googlegroups.com
Hi !

Is it possible to force a model to appear on the admin index page depending on the request ?

I'm asking because I did override the has_change_permission() method of the ModelAdmin, so that the user can be allowed to change some instances (chosen via a ManyToMany relationship between the user and the instances).

So, the idea is (in pseudocode):

if user.has_permission( change_permission ):
    he can manage all the instances -> display the model in the admin
else:
    if user.allowed_instances.count()>0:
        he can manage some instances -> display the model in the admin
    else:
        he cannot manage any instances -> do not display the model in the admin

Thanks !!

Olivier
Reply all
Reply to author
Forward
0 new messages