﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
11940	ModelForm evaluates callable default values on form class creation	Harm Geerts <hgeerts@…>	Luke Plant	"Using a ModelForm in combination with a field that defines a callable default value will cause the callable to be evaluated on form class creation.

{{{
class TestModel(models.Model):
    datetime = models.DateTimeField(default=datetime.datetime.now)

class TestModelForm(forms.ModelForm):
    class Meta:
        model = TestModel
}}}

{{{
>>> form = TestModelForm()
>>> print form['datetime']
<input type=""text"" name=""datetime"" value=""2009-09-23 16:49:34"" id=""id_datetime"" /><input type=""hidden"" name=""initial-datetime"" value=""2009-09-23 16:49:34.561971"" id=""id_datetime"" />
>>> # wait a bit
>>> form = TestModelForm()
>>> print form['datetime']
<input type=""text"" name=""datetime"" value=""2009-09-23 16:49:34"" id=""id_datetime"" /><input type=""hidden"" name=""initial-datetime"" value=""2009-09-23 16:49:34.561971"" id=""id_datetime"" />
}}}

The attached patch will fix this and preserve the callable default. It also implements Field.initial as a property that will evaluate callables when called.
I'm not sure this is desired but I found a case in the modeltests that depended on initial having a real value and I can imagine there is more code out there that expects this behaviour (in fact my regression test now depends on it). I'll leave it up to you to decide what to do with it.

The test case that depends on initial having a real value is in modeltests/model_formsets/models.py:886"		closed	Forms	dev		fixed		dev@… john@…	Ready for checkin	1	0	0	0	0	0
