From 530670e27f338923c0199dc274f2ecf71af5d762 Mon Sep 17 00:00:00 2001 From: Brian Rosner Date: Wed, 11 Jun 2008 03:58:01 +0000 Subject: newforms-admin: Fixed #6075 -- Implemented max_num on formsets and model formsets. Added a hook on InlineModelAdmin to customize in the admin interface. git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7613 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- docs/modelforms.txt | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'docs/modelforms.txt') diff --git a/docs/modelforms.txt b/docs/modelforms.txt index b9332bc59e..f2222c1fc0 100644 --- a/docs/modelforms.txt +++ b/docs/modelforms.txt @@ -449,6 +449,34 @@ model instances without any database interaction:: This gives you the ability to attach data to the instances before saving them to the database. +Limiting the number of objects editable +--------------------------------------- + +Similar to regular formsets you can use the ``max_num`` parameter to +``modelformset_factory`` to limit the number of forms displayed. With +model formsets this will properly limit the query to only select the maximum +number of objects needed:: + + >>> Author.objects.order_by('name') + [, , ] + + >>> AuthorFormSet = modelformset_factory(Author, max_num=2, extra=1) + >>> formset = AuthorFormSet(queryset=Author.objects.order_by('name')) + >>> formset.initial + [{'id': 1, 'name': u'Charles Baudelaire'}, {'id': 3, 'name': u'Paul Verlaine'}] + +If the value of ``max_num`` is less than the total objects returned it will +fill the rest with extra forms:: + + >>> AuthorFormSet = modelformset_factory(Author, max_num=4, extra=1) + >>> formset = AuthorFormSet(queryset=Author.objects.order_by('name')) + >>> for form in formset.forms: + ... print form.as_table() + + + + + Using ``inlineformset_factory`` ------------------------------- -- cgit v1.3