Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

It makes sense that when you subclass an existing model field, you're…

… often

going to be using the same database column type. Made that properly
inheritable (previously it was using the class name), at the cost of a little
more verboseness.

This is very slightly backwards incompatible (for subclasses of existing fields
that were relying on the old default).

Fixed #6556.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@7133 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6a796690e67e73f98e92538273e7d2840f23c2b8 1 parent 343fa35
@malcolmt malcolmt authored
Showing with 60 additions and 12 deletions.
  1. +60 −12 django/db/models/fields/__init__.py
View
72 django/db/models/fields/__init__.py
@@ -447,6 +447,9 @@ def __init__(self, *args, **kwargs):
kwargs['blank'] = True
Field.__init__(self, *args, **kwargs)
+ def get_internal_type(self):
+ return "BooleanField"
+
def to_python(self, value):
if value in (True, False): return value
if value in ('t', 'True', '1'): return True
@@ -465,6 +468,9 @@ class CharField(Field):
def get_manipulator_field_objs(self):
return [oldforms.TextField]
+ def get_internal_type(self):
+ return "CharField"
+
def to_python(self, value):
if isinstance(value, basestring):
return value
@@ -495,6 +501,9 @@ def __init__(self, verbose_name=None, name=None, auto_now=False, auto_now_add=Fa
kwargs['blank'] = True
Field.__init__(self, verbose_name, name, **kwargs)
+ def get_internal_type(self):
+ return "DateField"
+
def to_python(self, value):
if value is None:
return value
@@ -564,6 +573,9 @@ def formfield(self, **kwargs):
return super(DateField, self).formfield(**defaults)
class DateTimeField(DateField):
+ def get_internal_type(self):
+ return "DateTimeField"
+
def to_python(self, value):
if value is None:
return value
@@ -634,6 +646,9 @@ def __init__(self, verbose_name=None, name=None, max_digits=None, decimal_places
self.max_digits, self.decimal_places = max_digits, decimal_places
Field.__init__(self, verbose_name, name, **kwargs)
+ def get_internal_type(self):
+ return "DecimalField"
+
def to_python(self, value):
if value is None:
return value
@@ -693,9 +708,6 @@ def __init__(self, *args, **kwargs):
kwargs['max_length'] = kwargs.get('max_length', 75)
CharField.__init__(self, *args, **kwargs)
- def get_internal_type(self):
- return "CharField"
-
def get_manipulator_field_objs(self):
return [oldforms.EmailField]
@@ -713,6 +725,9 @@ def __init__(self, verbose_name=None, name=None, upload_to='', **kwargs):
kwargs['max_length'] = kwargs.get('max_length', 100)
Field.__init__(self, verbose_name, name, **kwargs)
+ def get_internal_type(self):
+ return "FileField"
+
def get_db_prep_save(self, value):
"Returns field's value prepared for saving into a database."
# Need to convert UploadedFile objects provided via a form to unicode for database insertion
@@ -822,12 +837,18 @@ def __init__(self, verbose_name=None, name=None, path='', match=None, recursive=
def get_manipulator_field_objs(self):
return [curry(oldforms.FilePathField, path=self.path, match=self.match, recursive=self.recursive)]
+ def get_internal_type(self):
+ return "FilePathField"
+
class FloatField(Field):
empty_strings_allowed = False
def get_manipulator_field_objs(self):
return [oldforms.FloatField]
+ def get_internal_type(self):
+ return "FloatField"
+
def formfield(self, **kwargs):
defaults = {'form_class': forms.FloatField}
defaults.update(kwargs)
@@ -850,6 +871,9 @@ def contribute_to_class(self, cls, name):
if not self.height_field:
setattr(cls, 'get_%s_height' % self.name, curry(cls._get_FIELD_height, field=self))
+ def get_internal_type(self):
+ return "ImageField"
+
def save_file(self, new_data, new_object, original_object, change, rel, save=True):
FileField.save_file(self, new_data, new_object, original_object, change, rel, save)
# If the image has height and/or width field(s) and they haven't
@@ -872,6 +896,9 @@ class IntegerField(Field):
def get_manipulator_field_objs(self):
return [oldforms.IntegerField]
+ def get_internal_type(self):
+ return "IntegerField"
+
def formfield(self, **kwargs):
defaults = {'form_class': forms.IntegerField}
defaults.update(kwargs)
@@ -886,6 +913,9 @@ def __init__(self, *args, **kwargs):
def get_manipulator_field_objs(self):
return [oldforms.IPAddressField]
+ def get_internal_type(self):
+ return "IPAddressField"
+
def validate(self, field_data, all_data):
validators.isValidIPAddress4(field_data, None)
@@ -900,6 +930,9 @@ def __init__(self, *args, **kwargs):
kwargs['null'] = True
Field.__init__(self, *args, **kwargs)
+ def get_internal_type(self):
+ return "NullBooleanField"
+
def to_python(self, value):
if value in (None, True, False): return value
if value in ('None'): return None
@@ -919,6 +952,9 @@ class PhoneNumberField(IntegerField):
def get_manipulator_field_objs(self):
return [oldforms.PhoneNumberField]
+ def get_internal_type(self):
+ return "PhoneNumberField"
+
def validate(self, field_data, all_data):
validators.isValidPhone(field_data, all_data)
@@ -932,6 +968,9 @@ class PositiveIntegerField(IntegerField):
def get_manipulator_field_objs(self):
return [oldforms.PositiveIntegerField]
+ def get_internal_type(self):
+ return "PositiveIntegerField"
+
def formfield(self, **kwargs):
defaults = {'min_value': 0}
defaults.update(kwargs)
@@ -941,6 +980,9 @@ class PositiveSmallIntegerField(IntegerField):
def get_manipulator_field_objs(self):
return [oldforms.PositiveSmallIntegerField]
+ def get_internal_type(self):
+ return "PositiveSmallIntegerField"
+
def formfield(self, **kwargs):
defaults = {'min_value': 0}
defaults.update(kwargs)
@@ -955,14 +997,23 @@ def __init__(self, *args, **kwargs):
kwargs['db_index'] = True
super(SlugField, self).__init__(*args, **kwargs)
+ def get_internal_type(self):
+ return "SlugField"
+
class SmallIntegerField(IntegerField):
def get_manipulator_field_objs(self):
return [oldforms.SmallIntegerField]
+ def get_internal_type(self):
+ return "SmallIntegerField"
+
class TextField(Field):
def get_manipulator_field_objs(self):
return [oldforms.LargeTextField]
+ def get_internal_type(self):
+ return "TextField"
+
def formfield(self, **kwargs):
defaults = {'widget': forms.Textarea}
defaults.update(kwargs)
@@ -976,6 +1027,9 @@ def __init__(self, verbose_name=None, name=None, auto_now=False, auto_now_add=Fa
kwargs['editable'] = False
Field.__init__(self, verbose_name, name, **kwargs)
+ def get_internal_type(self):
+ return "TimeField"
+
def get_db_prep_lookup(self, lookup_type, value):
if settings.DATABASE_ENGINE == 'oracle':
# Oracle requires a date in order to parse.
@@ -1040,9 +1094,6 @@ def __init__(self, verbose_name=None, name=None, verify_exists=True, **kwargs):
def get_manipulator_field_objs(self):
return [oldforms.URLField]
- def get_internal_type(self):
- return "CharField"
-
def formfield(self, **kwargs):
defaults = {'form_class': forms.URLField, 'verify_exists': self.verify_exists}
defaults.update(kwargs)
@@ -1052,6 +1103,9 @@ class USStateField(Field):
def get_manipulator_field_objs(self):
return [oldforms.USStateField]
+ def get_internal_type(self):
+ return "USStateField"
+
def formfield(self, **kwargs):
from django.contrib.localflavor.us.forms import USStateSelect
defaults = {'widget': USStateSelect}
@@ -1063,9 +1117,6 @@ def __init__(self, verbose_name=None, name=None, schema_path=None, **kwargs):
self.schema_path = schema_path
Field.__init__(self, verbose_name, name, **kwargs)
- def get_internal_type(self):
- return "TextField"
-
def get_manipulator_field_objs(self):
return [curry(oldforms.XMLLargeTextField, schema_path=self.schema_path)]
@@ -1076,8 +1127,5 @@ def __init__(self, with_respect_to, **kwargs):
kwargs['null'] = True
IntegerField.__init__(self, **kwargs )
- def get_internal_type(self):
- return "IntegerField"
-
def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False, follow=True):
return [oldforms.HiddenField(name_prefix + self.name)]
Please sign in to comment.
Something went wrong with that request. Please try again.