November 2015
Beginner to intermediate
840 pages
26h 30m
English
ModelForm Inheritance to Connect TagForm to TagWe could now move on to our other forms, as our TagForm is fully functional. However, consider that to create our TagForm class, we reproduced the structure of our Tag model with form fields. Should we add or modify a field in Tag, we would need to mirror our actions in TagForm. We can avoid this scenario and maintain DRY if we connect TagForm to Tag. By changing the inheritance of TagForm from forms.Form to forms.ModelForm and connecting TagForm to Tag via a Meta nested class attribute, not only can we remove the list of declared form fields, but we can also remove the save() method, as it is now automatically provided to us. In /organizer/forms.py, we would thus have the code shown ...
Read now
Unlock full access