Skip to content

Commit

Permalink
No AutoField value validation, only a type cast for values going into…
Browse files Browse the repository at this point in the history
… the database.
  • Loading branch information
wrwrwr committed Mar 20, 2012
1 parent e201b6a commit 69ad031
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions django/db/models/fields/__init__.py
Expand Up @@ -451,9 +451,6 @@ class AutoField(Field):
description = _("Automatic key") description = _("Automatic key")


empty_strings_allowed = False empty_strings_allowed = False
default_error_messages = {
'invalid': _(u'This value must be of the %s type.'),
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
assert kwargs.get('primary_key', False) is True, "%ss must have primary_key=True." % self.__class__.__name__ assert kwargs.get('primary_key', False) is True, "%ss must have primary_key=True." % self.__class__.__name__
kwargs['blank'] = True kwargs['blank'] = True
Expand All @@ -466,14 +463,9 @@ def validate(self, value, model_instance):
pass pass


def get_db_prep_value(self, value, connection, prepared=False): def get_db_prep_value(self, value, connection, prepared=False):
type_ = connection.settings_dict.get('AUTOFIELD_TYPE', int)
if value is None: if value is None:
return value return value
try: return connection.settings_dict.get('AUTOFIELD_TYPE', int)(value)
return type_(value)
except (TypeError, ValueError):
raise exceptions.ValidationError(self.error_messages['invalid'] %
str(type_))


def contribute_to_class(self, cls, name): def contribute_to_class(self, cls, name):
assert not cls._meta.has_auto_field, "A model can't have more than one AutoField." assert not cls._meta.has_auto_field, "A model can't have more than one AutoField."
Expand Down

0 comments on commit 69ad031

Please sign in to comment.