summaryrefslogtreecommitdiff
path: root/django/db/models/base.py
diff options
context:
space:
mode:
authorJoseph Kocherhans <joseph@jkocherhans.com>2006-06-19 15:23:57 +0000
committerJoseph Kocherhans <joseph@jkocherhans.com>2006-06-19 15:23:57 +0000
commitadf4b9311d5d64a2bdd58da50271c121ea22e397 (patch)
treea69b3b023595cf1ce67a14c4c1ecd3290d94088e /django/db/models/base.py
parente976ed1f7910fad03704f88853c5c5b36cbab134 (diff)
downloaddjango-attic/multi-auth.tar.gz
multi-auth: Merged to [3151]archive/attic/multi-authattic/multi-auth
git-svn-id: http://code.djangoproject.com/svn/django/branches/multi-auth@3152 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/base.py')
-rw-r--r--django/db/models/base.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 3538826356..7242e6baa7 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -107,6 +107,12 @@ class Model(object):
else:
val = kwargs.pop(f.attname, f.get_default())
setattr(self, f.attname, val)
+ for prop in kwargs.keys():
+ try:
+ if isinstance(getattr(self.__class__, prop), property):
+ setattr(self, prop, kwargs.pop(prop))
+ except AttributeError:
+ pass
if kwargs:
raise TypeError, "'%s' is an invalid keyword argument for this function" % kwargs.keys()[0]
for i, arg in enumerate(args):
@@ -165,7 +171,7 @@ class Model(object):
cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % \
(backend.quote_name(self._meta.db_table),
','.join(['%s=%%s' % backend.quote_name(f.column) for f in non_pks]),
- backend.quote_name(self._meta.pk.attname)),
+ backend.quote_name(self._meta.pk.column)),
db_values + [pk_val])
else:
record_exists = False
@@ -183,9 +189,16 @@ class Model(object):
placeholders.append('(SELECT COUNT(*) FROM %s WHERE %s = %%s)' % \
(backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.order_with_respect_to.column)))
db_values.append(getattr(self, self._meta.order_with_respect_to.attname))
- cursor.execute("INSERT INTO %s (%s) VALUES (%s)" % \
- (backend.quote_name(self._meta.db_table), ','.join(field_names),
- ','.join(placeholders)), db_values)
+ if db_values:
+ cursor.execute("INSERT INTO %s (%s) VALUES (%s)" % \
+ (backend.quote_name(self._meta.db_table), ','.join(field_names),
+ ','.join(placeholders)), db_values)
+ else:
+ # Create a new record with defaults for everything.
+ cursor.execute("INSERT INTO %s (%s) VALUES (%s)" %
+ (backend.quote_name(self._meta.db_table),
+ backend.quote_name(self._meta.pk.column),
+ backend.get_pk_default_value()))
if self._meta.has_auto_field and not pk_set:
setattr(self, self._meta.pk.attname, backend.get_last_insert_id(cursor, self._meta.db_table, self._meta.pk.column))
transaction.commit_unless_managed()