Ticket #11108: delete_model@14387.diff

File delete_model@14387.diff, 3.2 KB (added by Florian Apolloner, 14 years ago)
  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index 12490c8..cd94bac 100644
    a b class ModelAdmin(BaseModelAdmin):  
    601601        """
    602602        obj.save()
    603603
     604    def delete_model(self, requet, obj):
     605        """
     606        Given a model instance delete it from the database.
     607        """
     608        obj.delete()
     609
    604610    def save_formset(self, request, form, formset, change):
    605611        """
    606612        Given an inline formset save it to the database.
    class ModelAdmin(BaseModelAdmin):  
    11191125                raise PermissionDenied
    11201126            obj_display = force_unicode(obj)
    11211127            self.log_deletion(request, obj, obj_display)
    1122             obj.delete()
     1128            self.delete_model(request, obj)
    11231129
    11241130            self.message_user(request, _('The %(name)s "%(obj)s" was deleted successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(obj_display)})
    11251131
  • docs/ref/contrib/admin/index.txt

    diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
    index 0550576..3fe83a8 100644
    a b templates used by the :class:`ModelAdmin` views:  
    756756``ModelAdmin`` methods
    757757----------------------
    758758
     759.. warning::
     760
     761    ``save_model`` and ``delete_model`` have to save/delete the object, those
     762    methods are not for veto purposes, they just allow you to do some extra
     763    operations.
     764
    759765.. method:: ModelAdmin.save_model(self, request, obj, form, change)
    760766
    761767The ``save_model`` method is given the ``HttpRequest``, a model instance,
    For example to attach ``request.user`` to the object prior to saving::  
    769775            obj.user = request.user
    770776            obj.save()
    771777
     778.. method:: ModelAdmin.delete_model(self, request, obj)
     779
     780The ``delete_model`` method is given the ``HttpRequest`` and a model instance.
     781Use this method to to pre- or post-delete operations.
     782
    772783.. method:: ModelAdmin.save_formset(self, request, form, formset, change)
    773784
    774785The ``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 1a939b0..0e9290c 100644
    a b database other than that that specified by your router chain, you'll  
    458458need to write custom :class:`~django.contrib.admin.ModelAdmin` classes
    459459that will direct the admin to use a specific database for content.
    460460
    461 ``ModelAdmin`` objects have four methods that require customization for
     461``ModelAdmin`` objects have five methods that require customization for
    462462multiple-database support::
    463463
    464464    class MultiDBModelAdmin(admin.ModelAdmin):
    multiple-database support::  
    469469            # Tell Django to save objects to the 'other' database.
    470470            obj.save(using=self.using)
    471471
     472        def delete_model(self, requqest, obj):
     473            # Tell Django to delete objects from the 'other' database
     474            obj.delete(using=self.using)
     475
    472476        def queryset(self, request):
    473477            # Tell Django to look for objects on the 'other' database.
    474478            return super(MultiDBModelAdmin, self).queryset(request).using(self.using)
Back to Top