Skip to content

Commit

Permalink
Docs update for Form.create/edit save customization
Browse files Browse the repository at this point in the history
  • Loading branch information
boxed committed Sep 21, 2024
1 parent d6c5471 commit 95d2c34
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/test_doc_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,28 @@ def disable_action(form, **_):
- `None` will result in the page being rendered like normal
- everything else iommi will attempt to json encode and return as a json response
"""


def test_customization_of_save_behavior():
# language=rst
"""
Customization of save behavior on `Form.create`/`edit`
------------------------------------------------------
There are some useful hooks for customizing the save behavior on `Form.create` and `Form.edit`. The most common use case
is to set some hardcoded value for a field that is not in the form. This is best done by using `Field.hardcoded`, so
that should be your first option.
Saving a model in Django models SQL quite closely and iommi have hooks for all the steps in a multi-step commit.
The callbacks are executed in this order:
- `extra__new_instance`: This is called to create a new instance of the model. By default it just calls `form.model()`.
- `extra__pre_save_all_but_related_fields` (only called for `Form.create`)
- `extra__on_save_all_but_related_fields` (only called for `Form.create`)
- `extra__pre_save` (before `instance.save()`)
- `extra__on_save` (after `instance.save()`)
After a POST is completed, the `extra__redirect` callback is executed if present, otherwise `extra__redirect_to`
is used to determine where to redirect to.
"""

0 comments on commit 95d2c34

Please sign in to comment.