Login

Add delete button in admin cp

Author:
cschand
Posted:
March 28, 2008
Language:
Python
Version:
.96
Score:
6 (after 6 ratings)

Add delete button on admin control panel to make delete as easy

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
from django.db import models

class Profile(models.Model):
    first_name = models.CharField(max_length=200)
    last_name = models.CharField(max_length=200, blank=True, null=True)
    address = models.TextField(max_length=1000, blank=True, null=True)

    def remove(self):
        return '<input type="button" value="Delete" onclick="location.href=\'%s/delete/\'" />' % (self.pk)

    remove.short_description = ''
    remove.allow_tags = True
    
    class Admin:
        list_display = ('first_name', 'last_name','address', 'remove')
        
    def __str__(self):
        return "%s %s" % (self.first_name, self.last_name)

More like this

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

Comments

Please login first before commenting.