From b307fb09bb615361ee296d0c1f8d1a7c4809f6dd Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Mon, 1 Aug 2005 16:26:39 +0000 Subject: 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 --- django/core/meta.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'django') 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) -- cgit v1.3