Summary
This chapter provided a deep dive into forms. We saw how to enhance Django forms with custom validation advanced rules for cleaning data and validating fields. We also saw how custom cleaning methods can transform the data that we get out of forms. A nice feature we saw that can be added to forms is the ability to set initial and placeholder values on fields so that the user does not have to fill them out.
We then looked at how to use the ModelForm
class to automatically create a form from a Django model. We saw how to only show some fields to the user and how to apply custom form validation rules to the ModelForm
. We also saw how Django can automatically save the new or updated model instance to the database inside the view. In the activities for this chapter, we enhanced Bookr some more by adding forms for creating and editing publishers and submitting reviews.
In the next chapter, we will continue with the theme of submitting user input, and we’ll discuss how...