So I've defined some fields as choices:
class MyModel(models.Model):
# Text language.
ENGLISH = 'eng'
FRENCH = 'fr'
LANGUAGES_CHOICES = [
(ENGLISH, 'English'),
(FRENCH, 'French'),
]
language = models.CharField(
max_length=max(len(language) for language in LANGUAGES_CHOICES),
choices=LANGUAGES_CHOICES,
blank=False,
null=True)
However, I can do MyModel(language='hurhurhur').save()
without any error or complaint. What am I missing?
Django validates a model when you validate a modelform, or if you explicitly call modelinst.full_clean() Calling modelinst.save() doesn't validate.