Login

Add delete button in admin cp

Author:
cschand
Posted:
March 28, 2008
Language:
Python
Version:
.96
Tags:
admin delete
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. Add delete buttons to admin changelist by kylefox 8 years ago
  2. Add buttons in admin forms by mamat 6 years, 8 months ago
  3. Improved Button Admin by kunitoki 3 years, 3 months ago
  4. URLField admin widget with View Link button by ungenio41 5 years ago
  5. Add admin edit form buttons (work with django 1.6) by shoreward 1 year, 5 months ago

Comments

Please login first before commenting.