Code

Ticket #10845: partial_modelform_note.diff

File partial_modelform_note.diff, 1.1 KB (added by adurdin, 5 years ago)

Docs patch

Line 
1Index: docs/topics/forms/modelforms.txt
2===================================================================
3--- docs/topics/forms/modelforms.txt    (revision 10682)
4+++ docs/topics/forms/modelforms.txt    (working copy)
5@@ -326,14 +326,21 @@
6     for the missing, but required fields, or use ``save(commit=False)`` and
7     manually set any extra required fields::
8 
9-        instance = Instance(required_field='value')
10-        form = InstanceForm(request.POST, instance=instance)
11-        new_instance = form.save()
12+        class PartialAuthorForm(ModelForm):
13+            class Meta:
14+                model = Author
15+                fields = ('name',)
16 
17-        instance = form.save(commit=False)
18-        instance.required_field = 'new value'
19-        new_instance = instance.save()
20+        author = Author(title='MR')
21+        form = PartialAuthorForm(request.POST, instance=author)
22+        new_author = form.save()
23 
24+        # or:
25+
26+        author = form.save(commit=False)
27+        author.title = 'MR'
28+        new_author = author.save()
29+
30     See the `section on saving forms`_ for more details on using
31     ``save(commit=False)``.
32