When I save a value for datetime through a POST request, it gets saved in the database (I verify by logging the value by quering for it afterwards). But when I reload my page, the value is set to 0000-00-00 00:00:00
# models.py
class Assignment(models.Model):
temp = models.CharField(max_length = 32)
deadline = models.DateTimeField(default=lambda: datetime.datetime.now() + datetime.timedelta(days=14))
# views.py
def some_function(request):
deadline = request.POST['deadline']
assignment.deadline = datetime.timedelta(int(deadline)) + datetime.datetime.now()
When I log the assignment.deadline value throughout this function, it’s always what I expect it to be (the current date + whatever the value in the POST request was).
However, when the page reloads, the value is set back to 0000-00-00 00:00:00
Why is this happening?
Aren’t you forgetting to call your assignment’s save() method?