0
@@ -369,3 +369,40 @@ There are a couple of things to note, however.
0
Chances are these notes won't affect you unless you're trying to do something
0
tricky with subclassing.
0
+Similar to regular formsets there are a couple enhanced formset classes that
0
+provide all the right things to work with your models. Lets reuse the
0
+``Author`` model from above::
0
+ >>> from django.newforms.models import modelformset_factory
0
+ >>> AuthorFormSet = modelformset_factory(Author)
0
+This will create a formset that is capable of working with the data associated
0
+to the ``Author`` model. It works just like a regular formset::
0
+ >>> formset = AuthorFormSet()
0
+ <input type="hidden" name="form-TOTAL_FORMS" value="1" id="id_form-TOTAL_FORMS" /><input type="hidden" name="form-INITIAL_FORMS" value="0" id="id_form-INITIAL_FORMS" />
0
+ <tr><th><label for="id_form-0-name">Name:</label></th><td><input id="id_form-0-name" type="text" name="form-0-name" maxlength="100" /></td></tr>
0
+ <tr><th><label for="id_form-0-title">Title:</label></th><td><select name="form-0-title" id="id_form-0-title">
0
+ <option value="" selected="selected">---------</option>
0
+ <option value="MR">Mr.</option>
0
+ <option value="MRS">Mrs.</option>
0
+ <option value="MS">Ms.</option>
0
+ <tr><th><label for="id_form-0-birth_date">Birth date:</label></th><td><input type="text" name="form-0-birth_date" id="id_form-0-birth_date" /><input type="hidden" name="form-0-id" id="id_form-0-id" /></td></tr>
0
+One thing to note is that ``modelformset_factory`` uses ``formset_factory``
0
+and by default turns ``can_delete`` to ``True``.
0
+By default when you create a formset from a model the queryset will be all
0
+objects in the model. This is best shown as ``Author.objects.all()``. This is
0
+ >>> formset = AuthorFormSet(queryset=Author.objects.filter(name__startswith='O'))
Comments
No one has commented yet.