Corrected code-block directives in topics/forms/formsets.txt.

This commit is contained in:
Mitchina 2024-03-08 07:10:36 +01:00 committed by Mariusz Felisiak
parent 1570ef02f3
commit 2d3531af23
1 changed files with 16 additions and 12 deletions

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