Hello. If I had a model like so:
class Article(models.Model):
headline = models.CharField(
max_length=200,
null=True,
blank=True,
help_text='Use puns liberally',
)
content = models.TextField()
And a modelform like so:
class ArticleForm(ModelForm):
class Meta:
model = Article
fields = ['headline', 'content']
How would I apply all of the attributes on the model field, on my form field. E.g if the headline
field in the form is over 200 characters, and max_length=200
is specified on the headline
model field, would a ValidationError be raised automatically?
Or would I have to override the headline
field itself in the form like below to ensure a ValidationError gets raised? Thanks.
class ArticleForm(ModelForm):
headline = forms.CharField(
max_length=200,
required=False,
help_text='Use puns liberally',
)
class Meta:
model = Article
fields = ['headline', 'content']