Login

Multiple Delete in Admin

Author:
gfranxman
Posted:
March 2, 2008
Language:
Python
Version:
.96
Score:
1 (after 1 ratings)

This snippet demonstrates the use of the SpecialOps patch ( link here )to the django 0.96 admin. Once you have the patch, adding actions like these is simple.

You can use the @admin_action decorator on model and manager methods to expose them inside the admin. For manager methods, the method should accept a list of IDs. For model methods, only self should be required.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from django.contrib.admin.decorators import admin_action

# inside CommentManager in django.contrib.comments.models


    @admin_action( name='Delete selected posts' )
    def multi_delete( self, id_list ):
        res = ""
        for id in id_list:
            obj = self.get( pk=id )
            res += repr( obj )
            obj.delete()
            res += "<br/>\n"
        return "Deleted %s" % res

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 10 months, 3 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
  5. Help text hyperlinks by sa2812 1 year, 7 months ago

Comments

Please login first before commenting.