所以我有下面的代碼:Model.objects.create執行full_clean的等價物?
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)
當我做MyModel(language='invalid').save()
或MyModel.objects.create(language='invalid')
,該模型保存毫無怨言。是否有任何方便的方法相當於Model.objects.create
,在保存前執行full_clean
?