A tricky little devil this one. For instance, you've got a "created" date in your form and you need it to be set to the current date whenever the page is displayed.
So immediately you go and do this
1.
class
SomeForm(forms.Form):
2.
test_datetime
=
forms.SplitDateTimeField(initial
=
datetime.datetime.now())
First load, sweet it works. But load the page again, and you'll realise the date is still the same! FUUUUUUUUU!
It seems that the initial date/time is resolved when the server is first initiated. So, how do we fix that?
Easy!
1.
class
SomeForm(forms.Form):
2.
test_datetime
=
forms.SplitDateTimeField(initial
=
datetime.datetime.now)
Can you spot the difference?
Just remove the () from now(). That's it! If we pass it a function, it'll evaluate it on display.