diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index f78c81ae39..4ae9a813fd 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -447,6 +447,9 @@ class BooleanField(Field): 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 @@ class DateField(Field): 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 @@ class DateField(Field): 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 @@ class DecimalField(Field): 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 @@ class EmailField(CharField): 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 @@ class FileField(Field): 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 @@ class FilePathField(Field): 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 @@ class ImageField(FileField): 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 @@ class IPAddressField(Field): 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 @@ class NullBooleanField(Field): 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 @@ class SlugField(CharField): 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 @@ class TimeField(Field): 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 @@ class URLField(CharField): 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 @@ class XMLField(TextField): 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 @@ class OrderingField(IntegerField): 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)]