Ticket #13524: 13524.1.diff
File 13524.1.diff, 9.9 KB (added by , 15 years ago) |
---|
-
docs/ref/contrib/admin/index.txt
diff -r b126ac58b50a docs/ref/contrib/admin/index.txt
a b 1053 1053 passed through to ``inlineformset_factory`` when creating the formset for this 1054 1054 inline. 1055 1055 1056 .. _ref-contrib-admin-inline-extra: 1057 1056 1058 ``extra`` 1057 1059 ~~~~~~~~~ 1058 1060 … … 1062 1064 1063 1065 .. versionadded:: 1.2 1064 1066 1065 Extra forms for inlines will be hidden and replaced with a link to dynamically 1066 add any number of new inlines for users with Javascript enabled. 1067 Extra forms for inlines will be hidden and replaced with a "Add another" link to 1068 dynamically add any number of new inlines for users with JavaScript enabled. 1069 1070 That dynamic will not appear if ``max_num`` is less than the number of currently 1071 displayed forms. 1072 1073 .. _ref-contrib-admin-inline-max-num: 1067 1074 1068 1075 ``max_num`` 1069 1076 ~~~~~~~~~~~ -
docs/releases/1.2.txt
diff -r b126ac58b50a docs/releases/1.2.txt
a b 351 351 only time this should ever be an issue is if you were expecting printing the 352 352 ``repr`` of a ``BooleanField`` to print ``1`` or ``0``. 353 353 354 Changed semantics of ``max_num`` in formsets, model formsets 355 ------------------------------------------------------------ 356 357 As part of enhancements made to the handling of formsets and model formsets, 358 the semantics and default values of the ``max_admin`` parameters to the 359 :ref:`django.forms.formsets.formset_factory() <formsets-max-num>` and 360 :ref:`django.forms.models.modelformset_factory() <model-formsets-max-num>` 361 functions have been changed in 1.2. 362 363 Previously, the default values for these parameters were ``0`` (zero) and they 364 indicated no limit had to be imposed by the formset machinery to the number of 365 generated forms. Starting with 1.2, the value used to specify that is ``None`` 366 and it's also the new default value. This frees the ``0`` value so the developer 367 can use it to: 368 369 * For ``formset_factory()``: To force no form to be generated at all in the 370 formset when an instance is rendered, irrespective of the value of the 371 ``extra`` parameter or the value of the ``initial`` parameter passed to 372 the class ``__init__`` method. 373 374 * For ``modelformset_factory()``: To force no extra blank forms to exist 375 when an instance of the model formset class is rendered, irrespective of 376 the value of the ``extra`` parameter. The forms representing existing 377 model instances pased in the ``queryset`` parameter to the class 378 ``__init__`` method are always shown, no truncation of these forms is 379 performed. 380 381 As model formsets are the basis of the admin app inlines functionality, these 382 changes also apply to the equally-named ``max_num`` admin 383 ``(Tabular|Stacked)Inline`` :ref:`option <ref-contrib-admin-inline-max-num>`. 384 385 This means that if you were specifying a value of ``0`` for ``max_num`` or were 386 leaving its value out in one of these places relying on the previous default 387 values, then it is possible that you will need to review and modify your code in 388 such spots. 389 390 .. seealso:: 391 392 :ref:`1.2-js-assisted-inlines` 393 354 394 .. _deprecated-features-1.2: 355 395 356 396 Features deprecated in 1.2 … … 611 651 ``SpatialBackend`` 612 652 ^^^^^^^^^^^^^^^^^^ 613 653 614 Prior to the creation of the separate spatial backends, the 654 Prior to the creation of the separate spatial backends, the 615 655 ``django.contrib.gis.db.backend.SpatialBackend`` object was 616 656 provided as an abstraction to introspect on the capabilities of 617 657 the spatial database. All of the attributes and routines provided by … … 929 969 The currently used language code for Norwegian Bokmål ``no`` is being 930 970 replaced by the more common language code ``nb``, which should be updated 931 971 by translators from now on. 972 973 .. _1.2-js-assisted-inlines: 974 975 JavaScript-assisted handling of inline related objects in the admin app where available 976 --------------------------------------------------------------------------------------- 977 978 When using inline model formsets in the admin app, if the user browser has 979 JavaScript enabled then extra forms controlled by the ``extra`` 980 ``(Stacked|Tabular)Inline`` :ref:`option <ref-contrib-admin-inline-extra>` will 981 be hidden and replaced with a link to dynamically add any number of new inlines. -
docs/topics/forms/formsets.txt
diff -r b126ac58b50a docs/topics/forms/formsets.txt
a b 68 68 69 69 :ref:`Creating formsets from models with model formsets <model-formsets>`. 70 70 71 .. _formsets-max-num: 72 71 73 Limiting the maximum number of forms 72 74 ------------------------------------ 73 75 … … 83 85 84 86 .. versionchanged:: 1.2 85 87 86 If the value of ``max_num`` is geater than the number of existing related88 If the value of ``max_num`` is geater than the number of existing 87 89 objects, up to ``extra`` additional blank forms will be added to the formset, 88 90 so long as the total number of forms does not exceed ``max_num``. 89 91 … … 91 93 forms displayed. Please note that the default value of ``max_num`` was changed 92 94 from ``0`` to ``None`` in version 1.2 to allow ``0`` as a valid value. 93 95 94 .. versionadded:: 1.295 96 The dynamic "Add Another" link in the Django admin will not appear if97 ``max_num`` is less than the number of currently displayed forms.98 99 96 Formset validation 100 97 ------------------ 101 98 -
docs/topics/forms/modelforms.txt
diff -r b126ac58b50a docs/topics/forms/modelforms.txt
a b 661 661 662 662 .. versionchanged:: 1.2 663 663 664 As with regular formsets, you can use the ``max_num`` parameter to665 ``modelformset_factory`` to limit the number of extra forms displayed.664 As with regular formsets, you can use the ``max_num`` and ``extra`` parameters 665 to ``modelformset_factory`` to limit the number of extra forms displayed. 666 666 667 667 ``max_num`` does not prevent existing objects from being displayed:: 668 668 -
tests/modeltests/model_formsets/models.py
diff -r b126ac58b50a tests/modeltests/model_formsets/models.py
a b 368 368 369 369 >>> AuthorFormSet = modelformset_factory(Author, max_num=None, extra=3) 370 370 >>> formset = AuthorFormSet(queryset=qs) 371 >>> len(formset.forms) 372 6 371 373 >>> len(formset.extra_forms) 372 374 3 373 375 374 376 >>> AuthorFormSet = modelformset_factory(Author, max_num=4, extra=3) 375 377 >>> formset = AuthorFormSet(queryset=qs) 378 >>> len(formset.forms) 379 4 376 380 >>> len(formset.extra_forms) 377 381 1 378 382 379 383 >>> AuthorFormSet = modelformset_factory(Author, max_num=0, extra=3) 380 384 >>> formset = AuthorFormSet(queryset=qs) 385 >>> len(formset.forms) 386 3 381 387 >>> len(formset.extra_forms) 382 388 0 383 389 -
tests/regressiontests/forms/formsets.py
diff -r b126ac58b50a tests/regressiontests/forms/formsets.py
a b 599 599 600 600 # Base case for max_num. 601 601 602 # When not passed, max_num will take its default value of None, i.e. unlimited 603 # number of forms, only controlled by the value of the extra parameter. 604 605 >>> LimitedFavoriteDrinkFormSet = formset_factory(FavoriteDrinkForm, extra=3) 606 >>> formset = LimitedFavoriteDrinkFormSet() 607 >>> for form in formset.forms: 608 ... print form 609 <tr><th><label for="id_form-0-name">Name:</label></th><td><input type="text" name="form-0-name" id="id_form-0-name" /></td></tr> 610 <tr><th><label for="id_form-1-name">Name:</label></th><td><input type="text" name="form-1-name" id="id_form-1-name" /></td></tr> 611 <tr><th><label for="id_form-2-name">Name:</label></th><td><input type="text" name="form-2-name" id="id_form-2-name" /></td></tr> 612 613 # If max_num is 0 then no form is rendered at all. 614 615 >>> LimitedFavoriteDrinkFormSet = formset_factory(FavoriteDrinkForm, extra=3, max_num=0) 616 >>> formset = LimitedFavoriteDrinkFormSet() 617 >>> for form in formset.forms: 618 ... print form 619 602 620 >>> LimitedFavoriteDrinkFormSet = formset_factory(FavoriteDrinkForm, extra=5, max_num=2) 603 621 >>> formset = LimitedFavoriteDrinkFormSet() 604 622 >>> for form in formset.forms: … … 606 624 <tr><th><label for="id_form-0-name">Name:</label></th><td><input type="text" name="form-0-name" id="id_form-0-name" /></td></tr> 607 625 <tr><th><label for="id_form-1-name">Name:</label></th><td><input type="text" name="form-1-name" id="id_form-1-name" /></td></tr> 608 626 609 # Ensure th e that max_num has no affect when extra is less than max_forms.627 # Ensure that max_num has no effect when extra is less than max_num. 610 628 611 629 >>> LimitedFavoriteDrinkFormSet = formset_factory(FavoriteDrinkForm, extra=1, max_num=2) 612 630 >>> formset = LimitedFavoriteDrinkFormSet() … … 616 634 617 635 # max_num with initial data 618 636 637 # When not passed, max_num will take its default value of None, i.e. unlimited 638 # number of forms, only controlled by the values of the initial and extra 639 # parameters. 640 641 >>> initial = [ 642 ... {'name': 'Fernet and Coke'}, 643 ... ] 644 >>> LimitedFavoriteDrinkFormSet = formset_factory(FavoriteDrinkForm, extra=1) 645 >>> formset = LimitedFavoriteDrinkFormSet(initial=initial) 646 >>> for form in formset.forms: 647 ... print form 648 <tr><th><label for="id_form-0-name">Name:</label></th><td><input type="text" name="form-0-name" value="Fernet and Coke" id="id_form-0-name" /></td></tr> 649 <tr><th><label for="id_form-1-name">Name:</label></th><td><input type="text" name="form-1-name" id="id_form-1-name" /></td></tr> 650 651 # If max_num is 0 then no form is rendered at all, even if extra and initial 652 # are specified. 653 654 >>> initial = [ 655 ... {'name': 'Fernet and Coke'}, 656 ... {'name': 'Bloody Mary'}, 657 ... ] 658 >>> LimitedFavoriteDrinkFormSet = formset_factory(FavoriteDrinkForm, extra=1, max_num=0) 659 >>> formset = LimitedFavoriteDrinkFormSet(initial=initial) 660 >>> for form in formset.forms: 661 ... print form 662 619 663 # More initial forms than max_num will result in only the first max_num of 620 664 # them to be displayed with no extra forms. 621 665