summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2005-08-01 16:26:39 +0000
committerAdrian Holovaty <adrian@holovaty.com>2005-08-01 16:26:39 +0000
commitb307fb09bb615361ee296d0c1f8d1a7c4809f6dd (patch)
treedcd24dd3208358dcdf774cce7367f5ee9528d49b /django
parent1a8fc57bf6e4b86fe047d04fea2efe50296634d0 (diff)
Fixed #239 and #107 -- Changed model init() to use Field.get_default() if the value wasn't explicitly passed as a keyword argument. That means setting 'id=None' is no longer necessary, and you can leave off fields if you want them to have default values set.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@360 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/core/meta.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/django/core/meta.py b/django/core/meta.py
index a6ef27a526..98ce768f72 100644
--- a/django/core/meta.py
+++ b/django/core/meta.py
@@ -720,14 +720,13 @@ class Model:
# CORE METHODS #############################
def method_init(opts, self, *args, **kwargs):
+ if kwargs:
+ for f in opts.fields:
+ setattr(self, f.name, kwargs.pop(f.name, f.get_default()))
+ if kwargs:
+ raise TypeError, "'%s' is an invalid keyword argument for this function" % kwargs.keys()[0]
for i, arg in enumerate(args):
setattr(self, opts.fields[i].name, arg)
- for k, v in kwargs.items():
- try:
- opts.get_field(k, many_to_many=False)
- except FieldDoesNotExist:
- raise TypeError, "'%s' is an invalid keyword argument for this function" % k
- setattr(self, k, v)
def method_eq(opts, self, other):
return isinstance(other, self.__class__) and getattr(self, opts.pk.name) == getattr(other, opts.pk.name)