'Date field is not getting saved in the admin database
models.py
class Add_Timelog(models.Model):
project=models.ManyToManyField(Project)
client=models.ManyToManyField(Client)
Job=models.ManyToManyField(Add_Job)
#Date = models.DateField(max_length=100 ,auto_now_add=True,editable=True)
Date= models.DateField(default = datetime.date.today)
Hours=models.TimeField(null=True)
def __str__(self):
return str(self.Date)
settings.py
DATE_INPUT_FORMATS = ('%Y-%m-%d')
When I posted a date in the api for the date field it is getting posted. But when I look that in the admin database it is showing as '%' in the date field, and if I tried to change the entry it is getting stored as 'undefined' and while saving the entries it is throwing an error as "enter a valid date". kindly help me to resolve this issue. Attached the screenshot of admin for your reference.
Solution 1:[1]
The DATE_INPUT_FORMATS setting [Django-doc] expects an iterable of items, so:
DATE_INPUT_FORMATS = ['%Y-%m-%d']
or with a singleton tuple:
DATE_INPUT_FORMATS = ('%Y-%m-%d',)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Willem Van Onsem |
