summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2006-06-12 12:49:14 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2006-06-12 12:49:14 +0000
commit686c5a2f884b0b5f318a6dd6b6ba7d09ff0180f3 (patch)
treea77ca525d827963063f3f035bd499b69518b8443 /django
parentbff39bfb8cbc43bbeb78897c76583ab942927a0a (diff)
Fixed the empty model saving case so that it retrieves the primary key id. Also
updated the tests to test this case. git-svn-id: http://code.djangoproject.com/svn/django/trunk@3118 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/db/models/base.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 21609afb7e..787dcd026e 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -187,14 +187,14 @@ class Model(object):
cursor.execute("INSERT INTO %s (%s) VALUES (%s)" % \
(backend.quote_name(self._meta.db_table), ','.join(field_names),
','.join(placeholders)), db_values)
- 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))
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()
# Run any post-save hooks.