November 2015
Beginner to intermediate
840 pages
26h 30m
English
ModelFormWhen we inherited ModelForm, we were able to remove our implementation of save(), because ModelForm provides its own. However, unlike our simple implementation, the ModelForm version of save() allows for objects to be created and updated.
The inheritance of ModelForm allows us to pass objects to the subclassed form via the instance attribute, as shown in Example 7.23.
Example 7.23: Python Interpreter Code
>>> django_tag = Tag.objects.get(slug='django') >>> form = TagForm(instance=django_tag)
At the moment, if we run save(), nothing will happen because the data has not changed, and neither has the state of the form, as shown in Example 7.24.
Example 7.24: Python Interpreter ...
Read now
Unlock full access