diff options
| author | Brian Rosner <brosner@gmail.com> | 2008-08-11 17:20:47 +0000 |
|---|---|---|
| committer | Brian Rosner <brosner@gmail.com> | 2008-08-11 17:20:47 +0000 |
| commit | 8ad96b4d29da98d47df010d864bbab7e8f83a045 (patch) | |
| tree | d6b707021f28bc621a1e2fd3334ed241c2c75abc /docs | |
| parent | 58cd4902a71a3695dd6c21dc957f59c333db364c (diff) | |
Added back save_model that was removed from [8273] to allow for both pre- and post- operations around save in ModelAdmin.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8307 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/admin.txt | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/docs/admin.txt b/docs/admin.txt index dcff894c51..0e8eff374b 100644 --- a/docs/admin.txt +++ b/docs/admin.txt @@ -524,21 +524,19 @@ with an operator: ``ModelAdmin`` methods ---------------------- -``save_form(self, request, form, change)`` +``save_model(self, request, obj, form, change)`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The ``save_form`` method is given the ``HttpRequest``, a ``ModelForm`` -instance and a boolean value based on whether it is adding or changing the -object. +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. -This method should return an unsaved instance. For example to attach -``request.user`` to the object prior to saving:: +For example to attach ``request.user`` to the object prior to saving:: class ArticleAdmin(admin.ModelAdmin): - def save_form(self, request, form, change): - instance = form.save(commit=False) - instance.user = request.user - return instance + def save_model(self, request, obj, form, change): + obj.user = request.user + obj.save() ``save_formset(self, request, form, formset, change)`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -547,9 +545,7 @@ The ``save_formset`` method is given the ``HttpRequest``, the parent ``ModelForm`` instance and a boolean value baesed on whether it is adding or changing the parent object. -This method should return unsaved instances. These instances will later be -saved to the database. By default the formset will only return instances that -have changed. For example to attach ``request.user`` to each changed formset +For example to attach ``request.user`` to each changed formset model instance:: class ArticleAdmin(admin.ModelAdmin): @@ -557,7 +553,8 @@ model instance:: instances = formset.save(commit=False) for instance in instances: instance.user = request.user - return instances + instance.save() + formset.save_m2m() ``ModelAdmin`` media definitions -------------------------------- |
