0

I have around 50 admin models which have ModelAdmin as base class.Now I want to remove delete feature for all the 50 models. I think there are two ways.

  1. Redefine has_delete_permission method to return false and remove 'delete_selected' action for all the 50 models (lot of work).
  2. Do the same thing as mentioned above in django.contrib.admin.AdminModel. which means altering the source code.

I don't want to alter the sourcecode. Is their any other way to do this expect above two ways?

girishs
  • 121
  • 1
  • 8

1 Answers1

0

3 . Create a an admin mixin class that has these two adjustments, and add to base classes of your existing 50 ModelAdmins

4 . Monkeypatch ModelAdmin (will affect all models, not just your 50)

5 . Monkeypatch you admins (if it's all of your apps models you could just iterate through registered admins and match the ones belonging to your app)

I would personally go with 3. Are there maybe other things these ModelAdmin's have in common? Adding the base class/mixin is a one-off effort and then you could make other changes down the line very easily.

P.S.: If you want to make sure the models aren't deleted, it's probably advisable to make sure their default manager's QuerySet doesn't delete either: https://stackoverflow.com/a/6459797/640759

Community
  • 1
  • 1
Danny W. Adair
  • 12,498
  • 4
  • 43
  • 49
  • 1
    Its possible to remove site wide delete action using: `admin.site.disable_action('delete_selected')`. But how about 'Delete' option for each record? Is there a similar way? – girishs Apr 10 '12 at 04:26