Ticket #11108: delete_model@11970.diff

File delete_model@11970.diff, 3.5 KB (added by apollo13, 5 years ago)
  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index dab9170..d125978 100644
    a b from django.utils.text import capfirst, get_text_list 
    2222from django.utils.translation import ugettext as _
    2323from django.utils.translation import ungettext, ugettext_lazy
    2424from django.utils.encoding import force_unicode
    25 try:
    26     set
    27 except NameError:
    28     from sets import Set as set     # Python 2.3 fallback
    2925
    3026HORIZONTAL, VERTICAL = 1, 2
    3127# returns the <ul> class for a given radio_admin field
    class ModelAdmin(BaseModelAdmin): 
    577573        """
    578574        obj.save()
    579575
     576    def delete_model(self, requet, obj):
     577        """
     578        Given a model instance delete it from the database.
     579        """
     580        obj.delete()
     581
    580582    def save_formset(self, request, form, formset, change):
    581583        """
    582584        Given an inline formset save it to the database.
    class ModelAdmin(BaseModelAdmin): 
    10611063                raise PermissionDenied
    10621064            obj_display = force_unicode(obj)
    10631065            self.log_deletion(request, obj, obj_display)
    1064             obj.delete()
     1066            self.delete_model(request, obj)
    10651067
    10661068            self.message_user(request, _('The %(name)s "%(obj)s" was deleted successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(obj_display)})
    10671069
  • docs/ref/contrib/admin/index.txt

    diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
    index 97e9c8b..b5ded5b 100644
    a b that provides the standard appearance is used. 
    739739``ModelAdmin`` methods
    740740----------------------
    741741
     742.. warning::
     743
     744    ``save_model`` and ``delete_model`` have to save/delete the object, those
     745    methods are not for veto purposes, they just allow you to do some extra
     746    operations.
     747
    742748.. method:: ModelAdmin.save_model(self, request, obj, form, change)
    743749
    744750The ``save_model`` method is given the ``HttpRequest``, a model instance,
    For example to attach ``request.user`` to the object prior to saving:: 
    752758            obj.user = request.user
    753759            obj.save()
    754760
     761.. method:: ModelAdmin.delete_model(self, request, obj)
     762
     763The ``delete_model`` method is given the ``HttpRequest`` and a model instance.
     764Use this method to to pre- or post-delete operations.
     765
    755766.. method:: ModelAdmin.save_formset(self, request, form, formset, change)
    756767
    757768The ``save_formset`` method is given the ``HttpRequest``, the parent
  • docs/topics/db/multi-db.txt

    diff --git a/docs/topics/db/multi-db.txt b/docs/topics/db/multi-db.txt
    index 8c42613..ca3e27d 100644
    a b database other than ``default``, you need to write custom 
    191191:class:`~django.contrib.admin.ModelAdmin` classes that will direct the
    192192admin to use a specific database for content.
    193193
    194 There are four methods that require customization on a ModelAdmin
     194There are five methods that require customization on a ModelAdmin
    195195object::
    196196
    197197    class MultiDBModelAdmin(admin.ModelAdmin):
    object:: 
    202202            # Tell Django to save objects to the 'other' database
    203203            obj.save(using=self.using)
    204204
     205        def delete_model(self, requqest, obj):
     206            # Tell Django to delete objects from the 'other' database
     207            obj.delete(using=self.using)
     208
    205209        def queryset(self, request):
    206210            # Tell Django to look for objects on the 'other' database
    207211            return super(MultiDBModelAdmin, self).queryset(request).using(self.using)
Back to Top