22π
Add the blank=True
parameter to the definition of your date
field if you want that field to be optional.
From the docs:
Note that this is different than null. null is purely database-related, whereas blank is validation-related. If a field has blank=True, form validation will allow entry of an empty value. If a field has blank=False, the field will be required.
7π
The first step is to change your field description like so:
date = models.DateField(null=True, blank=True)
null=True
is insufficient because that is only a directive relevant to table creation, not to validation. null
and blank
are separate concepts because there are situations where you only want one and not the other.
By the way, in almost all cases a date
and a time
field can be compressed into one DateTimeField
.
1π
It looks like youβre using a library which in turn uses django.forms.ModelForm.
If this is the case, you can add blank=True to your DateField to resolve the issue.
class Event(models.Model):
title = models.CharField(max_length=200)
recurring = models.BooleanField()
day = models.CharField(max_length=20, blank=True)
date = models.DateField(null=True, blank=True)
time = models.TimeField()
description = models.CharField(max_length=500)
venue = models.CharField(max_length=200, blank=True)
venueAddress = models.CharField(max_length=200, blank=True)
venueCity = models.CharField(max_length=200, blank=True)
- Django KeyError: "'__name__' not in globals"
- How to prevent user to access login page in django when already logged in?