diff options
| author | Alex Gaynor <alex.gaynor@gmail.com> | 2010-06-09 15:31:19 +0000 |
|---|---|---|
| committer | Alex Gaynor <alex.gaynor@gmail.com> | 2010-06-09 15:31:19 +0000 |
| commit | 89fb7aa31044bd3d63302b82ab31e893fa0a43a6 (patch) | |
| tree | b8c2aeadf310469532c68e49b50a7e8b2b1284fb /django/db/models/fields | |
| parent | defc4948102b01f2048eb05d51358a22183f5790 (diff) | |
[soc2010/query-refactor] Introced NativeAutoField, also started with some basic MongoDB tests (really just very basic ORM tests), and introduced various APIs into the mongodb backend that were necessary for running unittests.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/query-refactor@13338 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/fields')
| -rw-r--r-- | django/db/models/fields/__init__.py | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 65b60a0173..0c9b603609 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -447,17 +447,32 @@ class Field(object): "Returns the value of this field in the given model instance." return getattr(obj, self.attname) -class AutoField(Field): +class BaseAutoField(Field): + empty_strings_allowed = False + + def __init__(self, *args, **kwargs): + assert kwargs.get('primary_key'), "%ss must have primary_key=True." % self.__class__.__name__ + kwargs['blank'] = True + super(BaseAutoField, self).__init__(*args, **kwargs) + + def contribute_to_class(self, cls, name): + assert not cls._meta.has_auto_field, "A model can't have more than one AutoField." + super(BaseAutoField, self).contribute_to_class(cls, name) + cls._meta.has_auto_field = True + cls._meta.auto_field = self + + def get_internal_type(self): + return "AutoField" + + def formfield(self, **kwargs): + return None + +class AutoField(BaseAutoField): description = _("Integer") - empty_strings_allowed = False default_error_messages = { 'invalid': _(u'This value must be an integer.'), } - def __init__(self, *args, **kwargs): - assert kwargs.get('primary_key', False) is True, "%ss must have primary_key=True." % self.__class__.__name__ - kwargs['blank'] = True - Field.__init__(self, *args, **kwargs) def to_python(self, value): if value is None: @@ -475,14 +490,10 @@ class AutoField(Field): return None return int(value) - def contribute_to_class(self, cls, name): - assert not cls._meta.has_auto_field, "A model can't have more than one AutoField." - super(AutoField, self).contribute_to_class(cls, name) - cls._meta.has_auto_field = True - cls._meta.auto_field = self - - def formfield(self, **kwargs): - return None +class NativeAutoField(BaseAutoField): + # TODO: eventually delegate validation and other such things to the + # backends. For now it's enough that this class exists. + pass class BooleanField(Field): empty_strings_allowed = False |
