Fixed #11108 -- added ModelAdmin.delete_model, a hook with which to perform custom pre-post delete behavior. Thanks to Florian Apolloner for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14673 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Alex Gaynor 2010-11-21 19:00:40 +00:00
parent 0cf1c96d06
commit 274aba3b9b
5 changed files with 49 additions and 4 deletions

View file

@ -757,6 +757,12 @@ templates used by the :class:`ModelAdmin` views:
``ModelAdmin`` methods
----------------------
.. warning::
:meth:`ModelAdmin.save_model` and :meth:`ModelAdmin.delete_model` must
save/delete the object, they are not for veto purposes, rather they allow
you to perform extra operations.
.. method:: ModelAdmin.save_model(self, request, obj, form, change)
The ``save_model`` method is given the ``HttpRequest``, a model instance,
@ -770,6 +776,13 @@ For example to attach ``request.user`` to the object prior to saving::
obj.user = request.user
obj.save()
.. method:: ModelAdmin.delete_model(self, request, obj)
.. versionadded:: 1.3
The ``delete_model`` method is given the ``HttpRequest`` and a model instance.
Use this method to do pre- or post-delete operations.
.. method:: ModelAdmin.save_formset(self, request, form, formset, change)
The ``save_formset`` method is given the ``HttpRequest``, the parent

View file

@ -458,7 +458,7 @@ database other than that that specified by your router chain, you'll
need to write custom :class:`~django.contrib.admin.ModelAdmin` classes
that will direct the admin to use a specific database for content.
``ModelAdmin`` objects have four methods that require customization for
``ModelAdmin`` objects have five methods that require customization for
multiple-database support::
class MultiDBModelAdmin(admin.ModelAdmin):
@ -469,6 +469,10 @@ multiple-database support::
# Tell Django to save objects to the 'other' database.
obj.save(using=self.using)
def delete_model(self, requqest, obj):
# Tell Django to delete objects from the 'other' database
obj.delete(using=self.using)
def queryset(self, request):
# Tell Django to look for objects on the 'other' database.
return super(MultiDBModelAdmin, self).queryset(request).using(self.using)