summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorDoug Harris <dharris@truthinitiative.org>2016-12-02 13:52:24 -0500
committerTim Graham <timograham@gmail.com>2016-12-08 08:21:59 -0500
commit413216fb9fb36c064494fe155effc39e2888161e (patch)
tree526cda2b6b70a865ce0333f5b8548dc23f7e9549 /docs
parent07ac5d830a90d75a1af1f95d78ed846f6c33d73f (diff)
Fixed #27566 -- Clarified overriding ModelAdmin.save_model()/delete_model() docs.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/contrib/admin/index.txt19
1 files changed, 12 insertions, 7 deletions
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
index ab80e1c9d1..fed034bd92 100644
--- a/docs/ref/contrib/admin/index.txt
+++ b/docs/ref/contrib/admin/index.txt
@@ -1326,15 +1326,18 @@ templates used by the :class:`ModelAdmin` views:
.. 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.
+ When overriding :meth:`ModelAdmin.save_model` and
+ :meth:`ModelAdmin.delete_model`, your code must save/delete the
+ object. They aren't meant for veto purposes, rather they allow you to
+ perform extra operations.
.. method:: ModelAdmin.save_model(request, obj, form, change)
The ``save_model`` method is given the ``HttpRequest``, a model instance,
- a ``ModelForm`` instance and a boolean value based on whether it is adding
- or changing the object. Here you can do any pre- or post-save operations.
+ a ``ModelForm`` instance, and a boolean value based on whether it is adding
+ or changing the object. Overriding this method allows doing pre- or
+ post-save operations. Call ``super().save_model()`` to save the object
+ using :meth:`.Model.save`.
For example to attach ``request.user`` to the object prior to saving::
@@ -1343,12 +1346,14 @@ templates used by the :class:`ModelAdmin` views:
class ArticleAdmin(admin.ModelAdmin):
def save_model(self, request, obj, form, change):
obj.user = request.user
- obj.save()
+ super(ArticleAdmin, self).save_model(request, obj, form, change)
.. method:: ModelAdmin.delete_model(request, obj)
The ``delete_model`` method is given the ``HttpRequest`` and a model
- instance. Use this method to do pre- or post-delete operations.
+ instance. Overriding this method allows doing pre- or post-delete
+ operations. Call ``super().delete_model()`` to delete the object using
+ :meth:`.Model.delete`.
.. method:: ModelAdmin.save_formset(request, form, formset, change)