diff options
| author | vgolubev <nakmak1998@gmail.com> | 2021-08-01 23:33:12 +0300 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-01-27 20:45:21 +0100 |
| commit | e87f57fdb8dcdabc452bd15abd015bf6c9b1f7a8 (patch) | |
| tree | 229f0d73438096bd90a93077b3fcda93f07e7151 /docs/topics/forms | |
| parent | 0af9a5fc7d765aa05ea784e2c3237675f3bb4b49 (diff) | |
Fixed #26142 -- Allowed model formsets to prevent new object creation.
Thanks Jacob Walls, David Smith, and Mariusz Felisiak for reviews.
Co-authored-by: parth <parthvin@gmail.com>
Diffstat (limited to 'docs/topics/forms')
| -rw-r--r-- | docs/topics/forms/modelforms.txt | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt index cf79fc69c4..3045cefd9e 100644 --- a/docs/topics/forms/modelforms.txt +++ b/docs/topics/forms/modelforms.txt @@ -953,8 +953,8 @@ extra forms displayed. Also, ``extra=0`` doesn't prevent creation of new model instances as you can :ref:`add additional forms with JavaScript <understanding-the-managementform>` -or send additional POST data. Formsets :ticket:`don't yet provide functionality -<26142>` for an "edit only" view that prevents creation of new instances. +or send additional POST data. See :ref:`model-formsets-edit-only` on how to do +this. If the value of ``max_num`` is greater than the number of existing related objects, up to ``extra`` additional blank forms will be added to the formset, @@ -972,6 +972,25 @@ so long as the total number of forms does not exceed ``max_num``:: A ``max_num`` value of ``None`` (the default) puts a high limit on the number of forms displayed (1000). In practice this is equivalent to no limit. +.. _model-formsets-edit-only: + +Preventing new objects creation +------------------------------- + +.. versionadded:: 4.1 + +Using the ``edit_only`` parameter, you can prevent creation of any new +objects:: + + >>> AuthorFormSet = modelformset_factory( + ... Author, + ... fields=('name', 'title'), + ... edit_only=True, + ... ) + +Here, the formset will only edit existing ``Author`` instances. No other +objects will be created or edited. + Using a model formset in a view ------------------------------- |
