summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorJoseph Kocherhans <joseph@jkocherhans.com>2007-12-13 02:48:04 +0000
committerJoseph Kocherhans <joseph@jkocherhans.com>2007-12-13 02:48:04 +0000
commite415eff0ead50882525129b0d5fd8ca95f1d30a7 (patch)
treebb29bfd43bd048153d992b270629ff41a04ad5a4 /django
parentf9410dc40d7a5a6ecbe42ea2ce8328fb3d22e89d (diff)
Fixed #6162. ModelForm's __init__ signature now matches Form's. This is a backwards incompatbile change. Based largely on a patch by ubernostrum.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6915 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/newforms/models.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/django/newforms/models.py b/django/newforms/models.py
index 4eb61761a1..8d6ee1fda2 100644
--- a/django/newforms/models.py
+++ b/django/newforms/models.py
@@ -262,11 +262,16 @@ class ModelFormMetaclass(type):
return type.__new__(cls, name, bases, attrs)
class BaseModelForm(BaseForm):
- def __init__(self, instance, data=None, files=None, auto_id='id_%s', prefix=None,
- initial=None, error_class=ErrorList, label_suffix=':'):
- self.instance = instance
+ def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
+ initial=None, error_class=ErrorList, label_suffix=':', instance=None):
opts = self._meta
- object_data = model_to_dict(instance, opts.fields, opts.exclude)
+ if instance is None:
+ # if we didn't get an instance, instantiate a new one
+ self.instance = opts.model()
+ object_data = {}
+ else:
+ self.instance = instance
+ object_data = model_to_dict(instance, opts.fields, opts.exclude)
# if initial was provided, it should override the values from instance
if initial is not None:
object_data.update(initial)