Reputation: 111
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.
Upvotes: 1
Views: 581
Reputation: 1
The tuple with only one value must have a trailing comma ,
as shown below:
DATE_INPUT_FORMATS = ('%Y-%m-%d',)
# A trailing comma ↑
In addition, the tuple with multiple values can omit a trailing comma ,
as shown below:
DATE_INPUT_FORMATS = ('%Y-%m-%d', '%m-%Y-%d')
# No trailing comma ↑
Upvotes: 0
Reputation: 477437
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',)
Upvotes: 1