Permalink
Browse files

Back to the original value_to_db_auto solution.

  • Loading branch information...
1 parent 69ad031 commit c68fd7ecc9882917d50c44e3bf1e07a8f183d7d5 @wrwrwr wrwrwr committed Mar 21, 2012
Showing with 10 additions and 3 deletions.
  1. +9 −0 django/db/backends/__init__.py
  2. +1 −3 django/db/models/fields/__init__.py
View
9 django/db/backends/__init__.py
@@ -673,6 +673,15 @@ def prep_for_like_query(self, x):
# need not necessarily be implemented using "LIKE" in the backend.
prep_for_iexact_query = prep_for_like_query
+ def value_to_db_auto(self, value):
+ """
+ Transform an AutoField value to an object compatible with what is expected
+ by the backend driver for automatic keys.
+ """
+ if value is None:
+ return None
+ return int(value)
+
def value_to_db_date(self, value):
"""
Transform a date value to an object compatible with what is expected
View
4 django/db/models/fields/__init__.py
@@ -463,9 +463,7 @@ def validate(self, value, model_instance):
pass
def get_db_prep_value(self, value, connection, prepared=False):
- if value is None:
- return value
- return connection.settings_dict.get('AUTOFIELD_TYPE', int)(value)
+ return connection.ops.value_to_db_auto(value)
def contribute_to_class(self, cls, name):
assert not cls._meta.has_auto_field, "A model can't have more than one AutoField."

0 comments on commit c68fd7e

Please sign in to comment.