1
0
mirror of https://github.com/django/django.git synced 2024-12-28 12:06:22 +00:00

[5.0.x] Corrected code-block directives in topics/forms/formsets.txt.

Backport of 2d3531af23 from main
This commit is contained in:
Mitchina 2024-03-08 07:10:36 +01:00 committed by Mariusz Felisiak
parent 5f07460a67
commit 3960bec41b

View File

@ -432,16 +432,18 @@ If ``validate_max=True`` is passed to
that the number of forms in the data set, minus those marked for
deletion, is less than or equal to ``max_num``.
.. code-block:: pycon
>>> from django.forms import formset_factory
>>> from myapp.forms import ArticleForm
>>> ArticleFormSet = formset_factory(ArticleForm, max_num=1, validate_max=True)
>>> data = {
... 'form-TOTAL_FORMS': '2',
... 'form-INITIAL_FORMS': '0',
... 'form-0-title': 'Test',
... 'form-0-pub_date': '1904-06-16',
... 'form-1-title': 'Test 2',
... 'form-1-pub_date': '1912-06-23',
... "form-TOTAL_FORMS": "2",
... "form-INITIAL_FORMS": "0",
... "form-0-title": "Test",
... "form-0-pub_date": "1904-06-16",
... "form-1-title": "Test 2",
... "form-1-pub_date": "1912-06-23",
... }
>>> formset = ArticleFormSet(data)
>>> formset.is_valid()
@ -475,16 +477,18 @@ If ``validate_min=True`` is passed to
that the number of forms in the data set, minus those marked for
deletion, is greater than or equal to ``min_num``.
.. code-block:: pycon
>>> from django.forms import formset_factory
>>> from myapp.forms import ArticleForm
>>> ArticleFormSet = formset_factory(ArticleForm, min_num=3, validate_min=True)
>>> data = {
... 'form-TOTAL_FORMS': '2',
... 'form-INITIAL_FORMS': '0',
... 'form-0-title': 'Test',
... 'form-0-pub_date': '1904-06-16',
... 'form-1-title': 'Test 2',
... 'form-1-pub_date': '1912-06-23',
... "form-TOTAL_FORMS": "2",
... "form-INITIAL_FORMS": "0",
... "form-0-title": "Test",
... "form-0-pub_date": "1904-06-16",
... "form-1-title": "Test 2",
... "form-1-pub_date": "1912-06-23",
... }
>>> formset = ArticleFormSet(data)
>>> formset.is_valid()