Hi, I am using Django 1.1. When I create a form, the initial data is set when the class is created. It does not get updated when an object is created. The following can demonstrate:
>>> >>> import datetime >>> from django import forms >>> >>> datetime.datetime.now() datetime.datetime(2010, 3, 4, 20, 11, 33, 477095) >>> >>> >>> class DateTest(forms.Form): ... in_date=forms.DateTimeField(initial=datetime.datetime.now()) ... >>> >>> datetime.datetime.now() datetime.datetime(2010, 3, 4, 20, 13, 5, 308900) >>> >>> >>> foo = DateTest() >>> >>> foo.as_p() u'<p><label for="id_in_date">In date:</label> <input type="text" name="in_date" value="2010-03-04 20:12:58" id="id_in_date" /></p>' >>> >>> >>> datetime.datetime.now() datetime.datetime(2010, 3, 4, 20, 13, 52, 540813) >>> >>> >>> >>> bar = DateTest() >>> >>> bar.as_p() u'<p><label for="id_in_date">In date:</label> <input type="text" name="in_date" value="2010-03-04 20:12:58" id="id_in_date" /></p>' >>> >>> >>> datetime.datetime.now() datetime.datetime(2010, 3, 4, 20, 15, 9, 644799) >>> >>> So as you can see, when the class was created, the tile was 20:12:58, and this was stored as initial data. Any new form object created after this time maintained the time of when the class was first initialized in memory rather than re-initializing whenever an object is created. I want this field to reflect the time of the object creation as opposed to the time of class creation. Is there any other way of doing this apart from setting the class variable at each object creation manually? In other words, is there a class initialization option that I can use, or settings option? Or do I by default just set the class variable by either overriding the __init__ constructor or setting it manually after object creation? -- 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.