public
Description: A high-level Python Web framework that encourages rapid development and clean, pragmatic design.
Homepage: http://www.djangoproject.com/
Clone URL: git://github.com/brosner/django.git
Search Repo:
Added a section on saving with model formsets.
brosner (author)
Mon May 12 16:43:05 -0700 2008
commit  3f0e4c525166c6b06958686f9c9030c424d5d276
tree    16972599f4d28d3f8db1ec2db4a60077cb59a34f
parent  1d14a8eb3063911b8ddf9a41cf0ff4d6b19780d8
...
408
409
410
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
411
412
413
...
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
0
@@ -408,6 +408,31 @@
0
 
0
     >>> formset = AuthorFormSet(queryset=Author.objects.filter(name__startswith='O'))
0
 
0
+Saving objects in the formset
0
+-----------------------------
0
+
0
+Similar to a ``ModelForm`` you can save the data into the model. This is done
0
+with the ``save()`` method on the formset::
0
+
0
+ # create a formset instance with POST data.
0
+ >>> formset = AuthorFormSet(request.POST)
0
+
0
+ # assuming all is valid, save the data
0
+ >>> instances = formset.save()
0
+
0
+The ``save()`` method will return the instances that have been saved to the
0
+database. If an instance did not change in the bound data it will not be
0
+saved to the database and not found in ``instances`` in the above example.
0
+
0
+You can optionally pass in ``commit=False`` to ``save()`` to only return the
0
+model instances without any database interaction::
0
+
0
+ # don't save to the database
0
+ >>> unsaved_instances = formset.save(commit=False)
0
+
0
+This gives you the ability to attach data to the instances before saving them
0
+to the database.
0
+
0
 Using ``inlineformset_factory``
0
 -------------------------------
0
 

Comments

    No one has commented yet.