From 65be56816fc173f823566728ab78b72d061bb466 Mon Sep 17 00:00:00 2001 From: Brian Rosner Date: Sat, 9 Aug 2008 20:52:40 +0000 Subject: Fixed #5780 -- Adjusted the ModelAdmin API to allow the created/updated objects to be passed to the formsets prior to validation. This is a backward incompatible change for anyone overridding save_add or save_change. They have been removed in favor of more granular methods introduced in [8266] and the new response_add and response_change nethods. save_model has been renamed to save_form due to its slightly changed behavior. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8273 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- docs/admin.txt | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'docs') diff --git a/docs/admin.txt b/docs/admin.txt index 6efef41da3..d9b3523c04 100644 --- a/docs/admin.txt +++ b/docs/admin.txt @@ -521,6 +521,44 @@ with an operator: Performs a full-text match. This is like the default search method but uses an index. Currently this is only available for MySQL. +``ModelAdmin`` methods +---------------------- + +``save_form(self, request, 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. + +This method should return an unsaved instance. 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 + +``save_formset(self, request, form, formset, change)`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +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 +model instance:: + + class ArticleAdmin(admin.ModelAdmin): + def save_formset(self, request, form, formset, change): + instances = formset.save(commit=False) + for instance in instances: + instance.user = request.user + return instances + ``ModelAdmin`` media definitions -------------------------------- -- cgit v1.3