models.py
class MyModel(models.Model):
pub_date = models.DateTimeField(default=timezone.now)
title = models.CharField(max_length=255, blank=False, null=
The widgets
option is for overriding the defaults. It doesn't work for your tos
field because you have declared tos = BooleanField()
in your form. See the note in the widgets docs for more information about this.
You can fix the issue by passing widget
when you declare the tos
field:
class MyModelForm(ModelForm):
tos = BooleanField(widget=CheckboxInput(attrs={'data-validation-error-msg': 'You have to agree to our terms and conditions'}))
class Meta:
model = models.MyModel
fields = ['title', 'text', 'tos']
widgets = {
'title': TextInput(attrs={'class': 'form-control', 'placeholder': 'Title'}),
'text': Textarea(attrs={'class': 'form-control', 'placeholder': 'Text'}),
}