views:

52

answers:

2

I have a custom action on a model Foo all set up and ready to go, complete with a new permission I've made.

Problem is, my administrators need the can_change_foo permission to view a change list and perform that custom action (which I don't want to award).

Is there an easier way to set this up without rewriting the model list admin view?

A: 

There is a horrid hack I can think of... Completely untested, obviously...

You could disable all other actions by overriding get_actions() and only allow for your custom action. Then you could follow T.Stone's suggestion here and completely disable links to edit individual instances of the model. What that would allow you to do is give your users the can_change_foo permission knowing that the only action they would be able to perform was yours.

Not pretty... Especially the part about not linking to the edit page...

Is re-writing the list admin view that bad? :-)

celopes
PS. Maybe it would be worth creating a ticket for a Django feature request in the lines of: "Custom admin actions that can be enabled based on custom permissions"?
celopes
Also - that suggestion to disable the links doesn't work for me in Firefox - the checkbox becomes "linked" and opens the edit object page.
thornomad
A: 

I ended up overriding the changelist_view() method on my ModelAdmin class, copying the defaults from django and just commenting out the permissions check. The list (at least the way I have it configured) doesn't have links to edit the individual objects, and even if it did, django raises a PermissionDenied if you try and edit an individual object. (since I never awarded the can_change permission).

It's a hack, and some monkeypatching, but until there's a separate permission for viewing a changelist, it works pretty well.

andrew