On 16 Feb 2010, at 08:13 , harryos wrote: > > hi > I am using a TimeField and want to set the default value as current > time.I know the field normalizes to a datetime.time object.In a > DateField ,I can put (default=datetime.date.today) and this will set > the current day .Similarly I tried (default=datetime.now().time) for > TimeField ..and can get a default time value when the page is > loaded.But after waiting for a couple of minutes,I loaded the page > again(without restarting the server) and the timevalue shown was the > old one ,not current time.
Argument are only evaluated once, so `default=datetime.now().time` sets the default to the `datetime.now().time` as it is when evaluated. Once. Just wrap the thing in a `lambda` and you should be good to go: `default=(lambda:datetime.now().time)` -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.