如何验证模型字段标题?例如,如果标题字段的每次使用都以“博客”一词开头。
models.py
class TitleAbstract(models.Model):
title = models.CharField(max_length=255)
class Meta:
abstract = True
class Blog(TitleAbstract):
..............
forms.py
class BlogForm(forms.ModelForm):
class Meta:
model = Blog
views.py
class BlogCreateView(CreateView):
model = Blog
action = 'created'