On 16 Feb 2010, at 13:29 , Matt Schinckel wrote: > > On Feb 16, 5:37 pm, Masklinn <maskl...@masklinn.net> wrote: >> 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 don't even need to do this. Just remove the () from > datetime.now(), and it will do what you want it to. > > If you pass in a callable as the default, this will be called each > time the object is created. > > Matt.
Except in this case he wants a `time` object, not a `datetime` one. Are you sure Django handles the coercion/conversion from `datetime` to `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.