mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user