diff options
| author | Tim Graham <timograham@gmail.com> | 2013-06-01 18:16:57 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-06-01 18:20:54 -0400 |
| commit | 61524b09cfa3b51643d0e79cbf0e1e08ede357ae (patch) | |
| tree | 20dcdebd8369c70d0d5a94d1b62dd06101176e08 /docs | |
| parent | 07a73a2714a504ae487112c1679977fccc19b159 (diff) | |
Fixed #18388 - Added InlineModelAdmin.get_max_num hook.
Thanks d.willy.c.c@ for the suggestion and Melevir and Areski Belaid for work
on the patch.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/contrib/admin/index.txt | 26 | ||||
| -rw-r--r-- | docs/releases/1.6.txt | 5 |
2 files changed, 29 insertions, 2 deletions
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt index 73ea74adc0..8f457e77ac 100644 --- a/docs/ref/contrib/admin/index.txt +++ b/docs/ref/contrib/admin/index.txt @@ -1728,6 +1728,11 @@ The ``InlineModelAdmin`` class adds: doesn't directly correlate to the number of objects, but can if the value is small enough. See :ref:`model-formsets-max-num` for more information. + .. versionadded:: 1.6 + + :meth:`InlineModelAdmin.get_max_num` also allows you to customize the + maximum number of extra forms. + .. attribute:: InlineModelAdmin.raw_id_fields By default, Django's admin uses a select-box interface (<select>) for @@ -1787,6 +1792,27 @@ The ``InlineModelAdmin`` class adds: return extra - obj.binarytree_set.count() return extra +.. method:: InlineModelAdmin.get_max_num(self, request, obj=None, **kwargs) + + .. versionadded:: 1.6 + + Returns the maximum number of extra inline forms to use. By default, + returns the :attr:`InlineModelAdmin.max_num` attribute. + + Override this method to programmatically determine the maximum number of + inline forms. For example, this may be based on the model instance + (passed as the keyword argument ``obj``):: + + class BinaryTreeAdmin(admin.TabularInline): + model = BinaryTree + + def get_max_num(self, request, obj=None, **kwargs): + max_num = 10 + if obj.parent: + return max_num - 5 + return max_num + + Working with a model with two or more foreign keys to the same parent model --------------------------------------------------------------------------- diff --git a/docs/releases/1.6.txt b/docs/releases/1.6.txt index cd665a775e..2dca61bfed 100644 --- a/docs/releases/1.6.txt +++ b/docs/releases/1.6.txt @@ -292,9 +292,10 @@ Minor features :meth:`~django.db.models.query.QuerySet.select_related` can be cleared using ``select_related(None)``. -* The :meth:`~django.contrib.admin.InlineModelAdmin.get_extra` method on +* The :meth:`~django.contrib.admin.InlineModelAdmin.get_extra` and + :meth:`~django.contrib.admin.InlineModelAdmin.get_max_num` methods on :class:`~django.contrib.admin.InlineModelAdmin` may be overridden to - customize the number of extra inline forms. + customize the extra and maximum number of inline forms. Backwards incompatible changes in 1.6 ===================================== |
