diff --git a/docs/topics/forms/formsets.txt b/docs/topics/forms/formsets.txt index d09a1a063f..1f49044e6e 100644 --- a/docs/topics/forms/formsets.txt +++ b/docs/topics/forms/formsets.txt @@ -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()