Robert Wittams wrote: > both auto_now and auto_now_add are quite hackish little puppies. > > auto_now should really be equivalent to a _pre_save that sets the field > to the current time. > > auto_now_add should really be equivalent to a non-editable field that > gets set to the current time on insert, and is just statically displayed > afterwards.
I think you got them reversed, I think auto_now currently works as intended. If you display it (your mistake I guess?) and edit it, it will still cram in the current time on insert. As for auto_now_add, I got rid of those and added, def _pre_save(self): import datetime if (self.date_posted == None): self.date_posted = datetime.datetime.today() if (self.time_posted == None): self.time_posted = datetime.datetime.strftime(datetime.datetime.now(), "%H:%M:%s") (by the way, for some reason date wants a datetime object, and time wants either a datetime object or a string, I think... if you give time a datetime object it won't insert H:M:S though (as it would if you set the time manually through the form) - it puts in the timezone too, etc. That's why I strftime the variable, if that makes any sense, I wanted it to be uniform across the column.