Django forms: default value if user leaves field blank
If you're using a ModelForm
simply follow Dan's advice.
If however you're simply using a Form
then you may have to specify how to deal with validation. Example Documentation
class YourForm(forms.Form):
...
def clean_field(self):
data = self.cleaned_data['field']
if not data:
data = 'default value'
return data
Set a default value in the model.
class YourModel(models.Model):
this_field = models.TextField(default="default_value")