1
0
mirror of https://github.com/django/django.git synced 2025-10-25 22:56:12 +00:00

Fixed #2108 -- allow saving of empty models, rather than just dropping them.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3115 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick
2006-06-08 15:14:06 +00:00
parent 29f55c8dbb
commit 7e2b888a2d
7 changed files with 24 additions and 0 deletions

View File

@@ -189,6 +189,12 @@ class Model(object):
','.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()))
transaction.commit_unless_managed()
# Run any post-save hooks.