summaryrefslogtreecommitdiff
path: root/django/newforms/forms.py
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2007-01-09 04:39:44 +0000
committerAdrian Holovaty <adrian@holovaty.com>2007-01-09 04:39:44 +0000
commit2e148d70647bfab640ab395fc98ba9492d061dad (patch)
tree3b9f7cd3b0de76506cfab4078f79fe29896a424b /django/newforms/forms.py
parent54b8277ffb4cad90fb65ca4edf69d8279b8df898 (diff)
newforms: Added 'initial' parameter to Form, which lets initial data be specified dynamically
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4297 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/newforms/forms.py')
-rw-r--r--django/newforms/forms.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/django/newforms/forms.py b/django/newforms/forms.py
index 4cc6cb4ebd..e1cc566b3b 100644
--- a/django/newforms/forms.py
+++ b/django/newforms/forms.py
@@ -39,11 +39,12 @@ class BaseForm(StrAndUnicode):
# class is different than Form. See the comments by the Form class for more
# information. Any improvements to the form API should be made to *this*
# class, not to the Form class.
- def __init__(self, data=None, auto_id='id_%s', prefix=None):
+ def __init__(self, data=None, auto_id='id_%s', prefix=None, initial=None):
self.is_bound = data is not None
self.data = data or {}
self.auto_id = auto_id
self.prefix = prefix
+ self.initial = initial or {}
self.__errors = None # Stores the errors after clean() has been called.
def __unicode__(self):
@@ -218,7 +219,7 @@ class BoundField(StrAndUnicode):
if auto_id and not attrs.has_key('id') and not widget.attrs.has_key('id'):
attrs['id'] = auto_id
if not self.form.is_bound:
- data = self.field.initial
+ data = self.form.initial.get(self.name, self.field.initial)
else:
data = self.data
return widget.render(self.html_name, data, attrs=attrs)