diff options
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 -------------------------------- |
