mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
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
This commit is contained in:
@@ -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
|
||||
--------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user