March 2020
Intermediate to advanced
608 pages
17h 17m
English
Database constraints don't affect form validation. They will just raise django.db.utils.IntegrityError if any data doesn't pass its conditions when saving entries to the database.
If you want to have data validated at the forms, you have to implement the validation in addition yourself, for example, in the clean() method of the model. That would look like this for the Idea model:
# myproject/apps/ideas/models.pyfrom django.db import modelsfrom django.conf import settingsfrom django.core.exceptions import ValidationErrorfrom django.utils.translation import gettext_lazy as _class Idea(models.Model): author = models.ForeignKey( settings.AUTH_USER_MODEL, verbose_name=_("Author"), on_delete=models.SET_NULL, blank=True, null=True, ...