I have the following model:
class Day(models.Model):
day = models.DateField()
title = models.CharField(max_length=20)
description = models.CharField(max_length=160)
votes = models.IntegerField(max_length=7)
last_vote = models.DateTimeField()
def __unicode__(self):
return self.title
Whenever I edit it like this:
current_time = datetime.datetime.now()
day_to_vote_for.votes += 1
day_to_vote_for.last_vote = current_time
day_to_vote_for.save()
or whenever I edit through the admin control panel, it is reset to a blank field? Why? This doesn’t happen with the Datetime field. How do I fix it?
People need to be able to specify dates other than now. So auto_now_add won’t work. It’s just clearing for no reason.
Just pass auto_now=True if you want the field to be updated with current timestamp whenever you save it or use auto_now_add=True to save the timestamp when the object was actually created.