Changeset 7612
- Timestamp:
- 06/10/08 14:58:25 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/newforms-admin/django/newforms/formsets.py
r7603 r7612 266 266 return mark_safe(u'\n'.join([unicode(self.management_form), forms])) 267 267 268 # XXX: This API *will* change. Use at your own risk. 269 def _formset_factory(form, formset=BaseFormSet, extra=1, can_order=False,can_delete=False):268 def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False, 269 can_delete=False): 270 270 """Return a FormSet for the given form class.""" 271 271 attrs = {'form': form, 'extra': extra, 'can_order': can_order, 'can_delete': can_delete} django/branches/newforms-admin/django/newforms/models.py
r7605 r7612 16 16 from widgets import Select, SelectMultiple, HiddenInput, MultipleHiddenInput 17 17 from widgets import media_property 18 from formsets import BaseFormSet, _formset_factory, DELETION_FIELD_NAME18 from formsets import BaseFormSet, formset_factory, DELETION_FIELD_NAME 19 19 20 20 __all__ = ( … … 378 378 form = modelform_factory(model, form=form, fields=fields, exclude=exclude, 379 379 formfield_callback=formfield_callback) 380 FormSet = _formset_factory(form, formset, extra=extra, can_order=can_order, can_delete=can_delete)380 FormSet = formset_factory(form, formset, extra=extra, can_order=can_order, can_delete=can_delete) 381 381 FormSet.model = model 382 382 return FormSet django/branches/newforms-admin/tests/regressiontests/forms/formsets.py
r7391 r7612 4 4 5 5 FormSet allows us to use multiple instance of the same form on 1 page. For now, 6 the best way to create a FormSet is by using the _formset_factory function.6 the best way to create a FormSet is by using the formset_factory function. 7 7 8 8 >>> from django.newforms import Form, CharField, IntegerField, ValidationError 9 >>> from django.newforms.formsets import _formset_factory, BaseFormSet9 >>> from django.newforms.formsets import formset_factory, BaseFormSet 10 10 11 11 >>> class Choice(Form): … … 13 13 ... votes = IntegerField() 14 14 15 >>> ChoiceFormSet = _formset_factory(Choice)15 >>> ChoiceFormSet = formset_factory(Choice) 16 16 17 17 A FormSet constructor takes the same arguments as Form. Let's create a FormSet … … 147 147 148 148 We can also display more than 1 empty form at a time. To do so, pass a 149 extra argument to _formset_factory.150 151 >>> ChoiceFormSet = _formset_factory(Choice, extra=3)149 extra argument to formset_factory. 150 151 >>> ChoiceFormSet = formset_factory(Choice, extra=3) 152 152 153 153 >>> formset = ChoiceFormSet(auto_id=False, prefix='choices') … … 243 243 244 244 We can easily add deletion ability to a FormSet with an agrument to 245 _formset_factory. This will add a boolean field to each form instance. When245 formset_factory. This will add a boolean field to each form instance. When 246 246 that boolean field is True, the form will be in formset.deleted_forms 247 247 248 >>> ChoiceFormSet = _formset_factory(Choice, can_delete=True)248 >>> ChoiceFormSet = formset_factory(Choice, can_delete=True) 249 249 250 250 >>> initial = [{'choice': u'Calexico', 'votes': 100}, {'choice': u'Fergie', 'votes': 900}] … … 291 291 292 292 We can also add ordering ability to a FormSet with an agrument to 293 _formset_factory. This will add a integer field to each form instance. When293 formset_factory. This will add a integer field to each form instance. When 294 294 form validation succeeds, [form.cleaned_data for form in formset.forms] will have the data in the correct 295 295 order specified by the ordering fields. If a number is duplicated in the set … … 298 298 something at the front of the list, you'd need to set it's order to 0. 299 299 300 >>> ChoiceFormSet = _formset_factory(Choice, can_order=True)300 >>> ChoiceFormSet = formset_factory(Choice, can_order=True) 301 301 302 302 >>> initial = [{'choice': u'Calexico', 'votes': 100}, {'choice': u'Fergie', 'votes': 900}] … … 372 372 Let's try throwing ordering and deletion into the same form. 373 373 374 >>> ChoiceFormSet = _formset_factory(Choice, can_order=True, can_delete=True)374 >>> ChoiceFormSet = formset_factory(Choice, can_order=True, can_delete=True) 375 375 376 376 >>> initial = [
