Skip to content

6. Forms

Once a visitor has decided which pet they're interested in, we need a way to accept adoption applications. We can use Django's ModelForm to build a submission form based on our existing model.

This chapter covers:

  • Model validation: Why save() doesn't check a model's rules, and how full_clean() and field validators do.
  • Forms: Building the application form from our model with ModelForm.
  • CreateView: Handling the form's GET and POST in a generic view, which saves the application and redirects after a successful submission.
  • Messages and logging: Confirming a submission with a one-time message, and writing a log message when an application is saved.