1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

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
This commit is contained in:
Adrian Holovaty
2005-08-01 16:26:39 +00:00
parent 1a8fc57bf6
commit b307fb09bb
5 changed files with 62 additions and 15 deletions

View File

@@ -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)