Author: russellm
Date: 2010-05-12 06:56:42 -0500 (Wed, 12 May 2010)
New Revision: 13241

Modified:
   django/trunk/docs/ref/contrib/admin/index.txt
   django/trunk/docs/releases/1.2.txt
   django/trunk/docs/topics/forms/formsets.txt
   django/trunk/docs/topics/forms/modelforms.txt
   django/trunk/tests/modeltests/model_formsets/models.py
   django/trunk/tests/regressiontests/forms/formsets.py
Log:
Fixed #13524 -- Added backwards compatibility and feature notes regarding admin 
inlines and formsets. Thanks to Ramiro Morales and Gabriel Hurley.

Modified: django/trunk/docs/ref/contrib/admin/index.txt
===================================================================
--- django/trunk/docs/ref/contrib/admin/index.txt       2010-05-12 11:07:50 UTC 
(rev 13240)
+++ django/trunk/docs/ref/contrib/admin/index.txt       2010-05-12 11:56:42 UTC 
(rev 13241)
@@ -1053,6 +1053,8 @@
 passed through to ``inlineformset_factory`` when creating the formset for this
 inline.
 
+.. _ref-contrib-admin-inline-extra:
+
 ``extra``
 ~~~~~~~~~
 
@@ -1062,9 +1064,16 @@
 
 .. versionadded:: 1.2
 
-Extra forms for inlines will be hidden and replaced with a link to dynamically
-add any number of new inlines for users with Javascript enabled.
+For users with JavaScript-enabled browsers, an "Add another" link is
+provided to enable any number of additional inlines to be added in
+addition to those provided as a result of the ``extra`` argument.
 
+The dynamic link will not appear if the number of currently displayed
+forms exceeds ``max_num``, or if the user does not have JavaScript
+enabled.
+
+.. _ref-contrib-admin-inline-max-num:
+
 ``max_num``
 ~~~~~~~~~~~
 

Modified: django/trunk/docs/releases/1.2.txt
===================================================================
--- django/trunk/docs/releases/1.2.txt  2010-05-12 11:07:50 UTC (rev 13240)
+++ django/trunk/docs/releases/1.2.txt  2010-05-12 11:56:42 UTC (rev 13241)
@@ -351,6 +351,39 @@
 only time this should ever be an issue is if you were expecting printing the
 ``repr`` of a ``BooleanField`` to print ``1`` or ``0``.
 
+Changes to the interpretation of``max_num`` in FormSets
+-------------------------------------------------------
+
+As part of enhancements made to the handling of FormSets, the default
+value and interpretation of the ``max_num`` parameter to the
+:ref:`django.forms.formsets.formset_factory() <formsets-max-num>` and
+:ref:`django.forms.models.modelformset_factory()
+<model-formsets-max-num>` functions has changed slightly. This
+change also affects the way the ``max_num`` argument is :ref:`used for
+inline admin objects <ref-contrib-admin-inline-max-num>`
+
+Previously, the default value for ``max_num`` was ``0`` (zero).
+FormSets then used the boolean value of ``max_num`` to determine if a
+limit was to be imposed on the number of generated forms. The default
+value of ``0`` meant that there was no default limit on the number of
+forms in a FormSet.
+
+Starting with 1.2, the default value for ``max_num`` has been changed
+to ``None``, and FormSets will differentiate between a value of
+``None`` and a value of ``0``. A value of ``None`` indicates that no
+limit on the number of forms is to be imposed; a value of ``0``
+indicates that a maximum of 0 forms should be imposed. This doesn't
+necessarily mean that no forms will be displayed -- see the
+:ref:`ModelFormSet documentation <model-formsets-max-num>` for more
+details.
+
+If you were manually specifying a value of ``0`` for ``max_num``, you
+will need to update your FormSet and/or admin definitions.
+
+.. seealso::
+
+    :ref:`1.2-js-assisted-inlines`
+
 .. _deprecated-features-1.2:
 
 Features deprecated in 1.2
@@ -611,7 +644,7 @@
 ``SpatialBackend``
 ^^^^^^^^^^^^^^^^^^
 
-Prior to the creation of the separate spatial backends, the 
+Prior to the creation of the separate spatial backends, the
 ``django.contrib.gis.db.backend.SpatialBackend`` object was
 provided as an abstraction to introspect on the capabilities of
 the spatial database.  All of the attributes and routines provided by
@@ -678,7 +711,12 @@
         sr_qs = SpatialRefSys.objects.using('my_spatialite').filter(...)
         gc_qs = GeometryColumns.objects.using('my_postgis').filter(...)
 
+Language code ``no``
+--------------------
 
+The currently used language code for Norwegian Bokmål ``no`` is being
+replaced by the more common language code ``nb``.
+
 What's new in Django 1.2
 ========================
 
@@ -923,9 +961,12 @@
 included with Django's and is no longer
 hosted separately at `geodjango.org <http://geodjango.org/>`_.
 
-Deprecation of old language code ``no``
----------------------------------------
+.. _1.2-js-assisted-inlines:
 
-The currently used language code for Norwegian Bokmål ``no`` is being
-replaced by the more common language code ``nb``, which should be updated
-by translators from now on.
+JavaScript-assisted handling of inline related objects in the admin
+-------------------------------------------------------------------
+
+If a user has JavaScript enabled in their browser, the interface for
+inline objects in the admin now allows inline objects to be
+dynamically added and removed. Users without JavaScript-enabled
+browsers will see no change in the behavior of inline objects.

Modified: django/trunk/docs/topics/forms/formsets.txt
===================================================================
--- django/trunk/docs/topics/forms/formsets.txt 2010-05-12 11:07:50 UTC (rev 
13240)
+++ django/trunk/docs/topics/forms/formsets.txt 2010-05-12 11:56:42 UTC (rev 
13241)
@@ -68,6 +68,8 @@
 
     :ref:`Creating formsets from models with model formsets <model-formsets>`.
 
+.. _formsets-max-num:
+
 Limiting the maximum number of forms
 ------------------------------------
 
@@ -83,7 +85,7 @@
 
 .. versionchanged:: 1.2
 
-If the value of ``max_num`` is geater than the number of existing related
+If the value of ``max_num`` is greater than the number of existing
 objects, up to ``extra`` additional blank forms will be added to the formset,
 so long as the total number of forms does not exceed ``max_num``.
 
@@ -91,11 +93,6 @@
 forms displayed. Please note that the default value of ``max_num`` was changed
 from ``0`` to ``None`` in version 1.2 to allow ``0`` as a valid value.
 
-.. versionadded:: 1.2
-
-The dynamic "Add Another" link in the Django admin will not appear if
-``max_num`` is less than the number of currently displayed forms.
-
 Formset validation
 ------------------
 

Modified: django/trunk/docs/topics/forms/modelforms.txt
===================================================================
--- django/trunk/docs/topics/forms/modelforms.txt       2010-05-12 11:07:50 UTC 
(rev 13240)
+++ django/trunk/docs/topics/forms/modelforms.txt       2010-05-12 11:56:42 UTC 
(rev 13241)
@@ -661,8 +661,8 @@
 
 .. versionchanged:: 1.2
 
-As with regular formsets, you can use the ``max_num`` parameter to
-``modelformset_factory`` to limit the number of extra forms displayed.
+As with regular formsets, you can use the ``max_num`` and ``extra`` parameters
+to ``modelformset_factory`` to limit the number of extra forms displayed.
 
 ``max_num`` does not prevent existing objects from being displayed::
 

Modified: django/trunk/tests/modeltests/model_formsets/models.py
===================================================================
--- django/trunk/tests/modeltests/model_formsets/models.py      2010-05-12 
11:07:50 UTC (rev 13240)
+++ django/trunk/tests/modeltests/model_formsets/models.py      2010-05-12 
11:56:42 UTC (rev 13241)
@@ -368,16 +368,22 @@
 
 >>> AuthorFormSet = modelformset_factory(Author, max_num=None, extra=3)
 >>> formset = AuthorFormSet(queryset=qs)
+>>> len(formset.forms)
+6
 >>> len(formset.extra_forms)
 3
 
 >>> AuthorFormSet = modelformset_factory(Author, max_num=4, extra=3)
 >>> formset = AuthorFormSet(queryset=qs)
+>>> len(formset.forms)
+4
 >>> len(formset.extra_forms)
 1
 
 >>> AuthorFormSet = modelformset_factory(Author, max_num=0, extra=3)
 >>> formset = AuthorFormSet(queryset=qs)
+>>> len(formset.forms)
+3
 >>> len(formset.extra_forms)
 0
 

Modified: django/trunk/tests/regressiontests/forms/formsets.py
===================================================================
--- django/trunk/tests/regressiontests/forms/formsets.py        2010-05-12 
11:07:50 UTC (rev 13240)
+++ django/trunk/tests/regressiontests/forms/formsets.py        2010-05-12 
11:56:42 UTC (rev 13241)
@@ -599,6 +599,24 @@
 
 # Base case for max_num.
 
+# When not passed, max_num will take its default value of None, i.e. unlimited
+# number of forms, only controlled by the value of the extra parameter.
+
+>>> LimitedFavoriteDrinkFormSet = formset_factory(FavoriteDrinkForm, extra=3)
+>>> formset = LimitedFavoriteDrinkFormSet()
+>>> for form in formset.forms:
+...     print form
+<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>
+<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>
+<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>
+
+# If max_num is 0 then no form is rendered at all.
+
+>>> LimitedFavoriteDrinkFormSet = formset_factory(FavoriteDrinkForm, extra=3, 
max_num=0)
+>>> formset = LimitedFavoriteDrinkFormSet()
+>>> for form in formset.forms:
+...     print form
+
 >>> LimitedFavoriteDrinkFormSet = formset_factory(FavoriteDrinkForm, extra=5, 
 >>> max_num=2)
 >>> formset = LimitedFavoriteDrinkFormSet()
 >>> for form in formset.forms:
@@ -606,7 +624,7 @@
 <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>
 <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>
 
-# Ensure the that max_num has no affect when extra is less than max_forms.
+# Ensure that max_num has no effect when extra is less than max_num.
 
 >>> LimitedFavoriteDrinkFormSet = formset_factory(FavoriteDrinkForm, extra=1, 
 >>> max_num=2)
 >>> formset = LimitedFavoriteDrinkFormSet()
@@ -616,6 +634,32 @@
 
 # max_num with initial data
 
+# When not passed, max_num will take its default value of None, i.e. unlimited
+# number of forms, only controlled by the values of the initial and extra
+# parameters.
+
+>>> initial = [
+...     {'name': 'Fernet and Coke'},
+... ]
+>>> LimitedFavoriteDrinkFormSet = formset_factory(FavoriteDrinkForm, extra=1)
+>>> formset = LimitedFavoriteDrinkFormSet(initial=initial)
+>>> for form in formset.forms:
+...     print form
+<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>
+<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>
+
+# If max_num is 0 then no form is rendered at all, even if extra and initial
+# are specified.
+
+>>> initial = [
+...     {'name': 'Fernet and Coke'},
+...     {'name': 'Bloody Mary'},
+... ]
+>>> LimitedFavoriteDrinkFormSet = formset_factory(FavoriteDrinkForm, extra=1, 
max_num=0)
+>>> formset = LimitedFavoriteDrinkFormSet(initial=initial)
+>>> for form in formset.forms:
+...     print form
+
 # More initial forms than max_num will result in only the first max_num of
 # them to be displayed with no extra forms.
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to