Model-level validation checks Django model values before saving them to the database. It helps ensure data can be stored and can enforce rules the database may not understand. section 4.8.1
Django separates database behavior from model and form behavior: null controls database storage, while blank controls whether Django Admin and web forms require a value. section 4.8.1
Common model-validation patterns include:
- EmailField checks that a value matches an email-address format, even when the database stores it as ordinary text. section 4.8.1
- choices restricts a field to predefined values and supplies display labels for Django Admin and web-form select controls. section 4.8.1
Country-code choices
A country field can use choices=[("US", "United States"), ("CA", "Canada"), ("MX", "Mexico")]. Django stores the code and displays the longer label. section 4.8.1
