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:
parent
29f55c8dbb
commit
7e2b888a2d
|
@ -131,6 +131,9 @@ def get_fulltext_search_sql(field_name):
|
|||
def get_drop_foreignkey_sql():
|
||||
return "DROP CONSTRAINT"
|
||||
|
||||
def get_pk_default_value():
|
||||
return "DEFAULT"
|
||||
|
||||
OPERATOR_MAPPING = {
|
||||
'exact': '= %s',
|
||||
'iexact': 'LIKE %s',
|
||||
|
|
|
@ -158,6 +158,9 @@ def get_fulltext_search_sql(field_name):
|
|||
def get_drop_foreignkey_sql():
|
||||
return "DROP FOREIGN KEY"
|
||||
|
||||
def get_pk_default_value():
|
||||
return "DEFAULT"
|
||||
|
||||
OPERATOR_MAPPING = {
|
||||
'exact': '= %s',
|
||||
'iexact': 'LIKE %s',
|
||||
|
|
|
@ -114,6 +114,9 @@ def get_fulltext_search_sql(field_name):
|
|||
def get_drop_foreignkey_sql():
|
||||
return "DROP FOREIGN KEY"
|
||||
|
||||
def get_pk_default_value():
|
||||
return "DEFAULT"
|
||||
|
||||
OPERATOR_MAPPING = {
|
||||
'exact': '= %s',
|
||||
'iexact': 'LIKE %s',
|
||||
|
|
|
@ -108,6 +108,9 @@ def get_fulltext_search_sql(field_name):
|
|||
def get_drop_foreignkey_sql():
|
||||
return "DROP CONSTRAINT"
|
||||
|
||||
def get_pk_default_value():
|
||||
return "DEFAULT"
|
||||
|
||||
# Register these custom typecasts, because Django expects dates/times to be
|
||||
# in Python's native (standard-library) datetime/time format, whereas psycopg
|
||||
# use mx.DateTime by default.
|
||||
|
|
|
@ -114,6 +114,9 @@ def get_fulltext_search_sql(field_name):
|
|||
def get_drop_foreignkey_sql():
|
||||
return "DROP CONSTRAINT"
|
||||
|
||||
def get_pk_default_value():
|
||||
return "DEFAULT"
|
||||
|
||||
OPERATOR_MAPPING = {
|
||||
'exact': '= %s',
|
||||
'iexact': 'ILIKE %s',
|
||||
|
|
|
@ -130,6 +130,9 @@ def get_fulltext_search_sql(field_name):
|
|||
def get_drop_foreignkey_sql():
|
||||
return ""
|
||||
|
||||
def get_pk_default_value():
|
||||
return "NULL"
|
||||
|
||||
def _sqlite_date_trunc(lookup_type, dt):
|
||||
try:
|
||||
dt = util.typecast_timestamp(dt)
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue