I have a simple model which looks like this:
class Group(models.Model):
name = models.CharField(max_length = 100, blank=False)
I would
From the Django docs in this case, your name will be stored as an empty string, because the null field option is False by default. if you want to define a custom default value, use the default field option.
name = models.CharField(max_length=100, blank=False, default='somevalue')
On this page, you can see that the blank is not database-related.
Update:
You should override the clean function of your model, to have custom validation, so your model def will be:
class Group(models.Model):
name = models.CharField(max_length=100, blank=False)
def clean(self):
from django.core.exceptions import ValidationError
if self.name == '':
raise ValidationError('Empty error message')
Or you can replace ValidationError to something else. Then before you call group.save() call group.full_clean() which will call clean()
Other validation related things are here.