Ticket #2365: DecimalField.diff

File DecimalField.diff, 11.7 KB (added by adurdin@…, 18 years ago)

Patch, also renames forms.FloatField (see #2366)

  • django/db/models/fields/__init__.py

     
    617617    def get_manipulator_field_objs(self):
    618618        return [curry(forms.FilePathField, path=self.path, match=self.match, recursive=self.recursive)]
    619619
    620 class FloatField(Field):
     620class DecimalField(Field):
    621621    empty_strings_allowed = False
    622622    def __init__(self, verbose_name=None, name=None, max_digits=None, decimal_places=None, **kwargs):
    623623        self.max_digits, self.decimal_places = max_digits, decimal_places
    624624        Field.__init__(self, verbose_name, name, **kwargs)
    625625
    626626    def get_manipulator_field_objs(self):
    627         return [curry(forms.FloatField, max_digits=self.max_digits, decimal_places=self.decimal_places)]
     627        return [curry(forms.DecimalField, max_digits=self.max_digits, decimal_places=self.decimal_places)]
    628628
    629629class ImageField(FileField):
    630630    def __init__(self, verbose_name=None, name=None, width_field=None, height_field=None, **kwargs):
  • django/db/backends/ado_mssql/creation.py

     
    77    'DateTimeField':     'smalldatetime',
    88    'FileField':         'varchar(100)',
    99    'FilePathField':     'varchar(100)',
    10     'FloatField':        'numeric(%(max_digits)s, %(decimal_places)s)',
     10    'DecimalField':      'numeric(%(max_digits)s, %(decimal_places)s)',
    1111    'ImageField':        'varchar(100)',
    1212    'IntegerField':      'int',
    1313    'IPAddressField':    'char(15)',
  • django/db/backends/postgresql/introspection.py

     
    8080    1114: 'DateTimeField',
    8181    1184: 'DateTimeField',
    8282    1266: 'TimeField',
    83     1700: 'FloatField',
     83    1700: 'DecimalField',
    8484}
  • django/db/backends/postgresql/creation.py

     
    1111    'DateTimeField':     'timestamp with time zone',
    1212    'FileField':         'varchar(100)',
    1313    'FilePathField':     'varchar(100)',
    14     'FloatField':        'numeric(%(max_digits)s, %(decimal_places)s)',
     14    'DecimalField':      'numeric(%(max_digits)s, %(decimal_places)s)',
    1515    'ImageField':        'varchar(100)',
    1616    'IntegerField':      'integer',
    1717    'IPAddressField':    'inet',
  • django/db/backends/sqlite3/creation.py

     
    1010    'DateTimeField':                'datetime',
    1111    'FileField':                    'varchar(100)',
    1212    'FilePathField':                'varchar(100)',
    13     'FloatField':                   'numeric(%(max_digits)s, %(decimal_places)s)',
     13    'DecimalField':                 'numeric(%(max_digits)s, %(decimal_places)s)',
    1414    'ImageField':                   'varchar(100)',
    1515    'IntegerField':                 'integer',
    1616    'IPAddressField':               'char(15)',
  • django/db/backends/mysql/introspection.py

     
    7676DATA_TYPES_REVERSE = {
    7777    FIELD_TYPE.BLOB: 'TextField',
    7878    FIELD_TYPE.CHAR: 'CharField',
    79     FIELD_TYPE.DECIMAL: 'FloatField',
     79    FIELD_TYPE.DECIMAL: 'DecimalField',
    8080    FIELD_TYPE.DATE: 'DateField',
    8181    FIELD_TYPE.DATETIME: 'DateTimeField',
    82     FIELD_TYPE.DOUBLE: 'FloatField',
    83     FIELD_TYPE.FLOAT: 'FloatField',
     82    FIELD_TYPE.DOUBLE: 'DecimalField',
     83    FIELD_TYPE.FLOAT: 'DecimalField',
    8484    FIELD_TYPE.INT24: 'IntegerField',
    8585    FIELD_TYPE.LONG: 'IntegerField',
    8686    FIELD_TYPE.LONGLONG: 'IntegerField',
  • django/db/backends/mysql/creation.py

     
    1111    'DateTimeField':     'datetime',
    1212    'FileField':         'varchar(100)',
    1313    'FilePathField':     'varchar(100)',
    14     'FloatField':        'numeric(%(max_digits)s, %(decimal_places)s)',
     14    'DecimalField':      'numeric(%(max_digits)s, %(decimal_places)s)',
    1515    'ImageField':        'varchar(100)',
    1616    'IntegerField':      'integer',
    1717    'IPAddressField':    'char(15)',
  • django/db/backends/oracle/introspection.py

     
    4848    1114: 'DateTimeField',
    4949    1184: 'DateTimeField',
    5050    1266: 'TimeField',
    51     1700: 'FloatField',
     51    1700: 'DecimalField',
    5252}
  • django/db/backends/oracle/creation.py

     
    77    'DateTimeField':     'date',
    88    'FileField':         'varchar2(100)',
    99    'FilePathField':     'varchar2(100)',
    10     'FloatField':        'number(%(max_digits)s, %(decimal_places)s)',
     10    'DecimalField':      'number(%(max_digits)s, %(decimal_places)s)',
    1111    'ImageField':        'varchar2(100)',
    1212    'IntegerField':      'integer',
    1313    'IPAddressField':    'char(15)',
  • django/db/backends/postgresql_psycopg2/introspection.py

     
    8080    1114: 'DateTimeField',
    8181    1184: 'DateTimeField',
    8282    1266: 'TimeField',
    83     1700: 'FloatField',
     83    1700: 'DecimalField',
    8484}
  • django/forms/__init__.py

     
    736736        if not 0 <= int(field_data) <= 32767:
    737737            raise validators.CriticalValidationError, gettext("Enter a whole number between 0 and 32,767.")
    738738
    739 class FloatField(TextField):
     739class DecimalField(TextField):
    740740    def __init__(self, field_name, max_digits, decimal_places, is_required=False, validator_list=None):
    741741        if validator_list is None: validator_list = []
    742742        self.max_digits, self.decimal_places = max_digits, decimal_places
  • django/core/management.py

     
    757757                if field_type == 'CharField' and row[3]:
    758758                    extra_params['maxlength'] = row[3]
    759759
    760                 if field_type == 'FloatField':
     760                if field_type == 'DecimalField':
    761761                    extra_params['max_digits'] = row[4]
    762762                    extra_params['decimal_places'] = row[5]
    763763
     
    831831                e.add(opts, '"%s": You can\'t use "id" as a field name, because each model automatically gets an "id" field if none of the fields have primary_key=True. You need to either remove/rename your "id" field or add primary_key=True to a field.' % f.name)
    832832            if isinstance(f, models.CharField) and f.maxlength in (None, 0):
    833833                e.add(opts, '"%s": CharFields require a "maxlength" attribute.' % f.name)
    834             if isinstance(f, models.FloatField):
     834            if isinstance(f, models.DecimalField):
    835835                if f.decimal_places is None:
    836                     e.add(opts, '"%s": FloatFields require a "decimal_places" attribute.' % f.name)
     836                    e.add(opts, '"%s": DecimalFields require a "decimal_places" attribute.' % f.name)
    837837                if f.max_digits is None:
    838                     e.add(opts, '"%s": FloatFields require a "max_digits" attribute.' % f.name)
     838                    e.add(opts, '"%s": DecimalFields require a "max_digits" attribute.' % f.name)
    839839            if isinstance(f, models.FileField) and not f.upload_to:
    840840                e.add(opts, '"%s": FileFields require an "upload_to" attribute.' % f.name)
    841841            if isinstance(f, models.ImageField):
  • django/contrib/admin/templatetags/admin_list.py

     
    151151            elif isinstance(f, models.BooleanField) or isinstance(f, models.NullBooleanField):
    152152                BOOLEAN_MAPPING = {True: 'yes', False: 'no', None: 'unknown'}
    153153                result_repr = '<img src="%simg/admin/icon-%s.gif" alt="%s" />' % (settings.ADMIN_MEDIA_PREFIX, BOOLEAN_MAPPING[field_val], field_val)
    154             # FloatFields are special: Zero-pad the decimals.
    155             elif isinstance(f, models.FloatField):
     154            # DecimalFields are special: Zero-pad the decimals.
     155            elif isinstance(f, models.DecimalField):
    156156                if field_val is not None:
    157157                    result_repr = ('%%.%sf' % f.decimal_places) % field_val
    158158                else:
  • django/contrib/admin/views/doc.py

     
    297297    'EmailField'                : _('E-mail address'),
    298298    'FileField'                 : _('File path'),
    299299    'FilePathField'             : _('File path'),
    300     'FloatField'                : _('Decimal number'),
     300    'DecimalField'              : _('Decimal number'),
    301301    'ForeignKey'                : _('Integer'),
    302302    'ImageField'                : _('File path'),
    303303    'IntegerField'              : _('Integer'),
  • tests/modeltests/invalid_models/models.py

     
    88
    99class FieldErrors(models.Model):
    1010    charfield = models.CharField()
    11     floatfield = models.FloatField()
     11    decimalfield = models.DecimalField()
    1212    filefield = models.FileField()
    1313    prepopulate = models.CharField(maxlength=10, prepopulate_from='bad')
    1414    choices = models.CharField(maxlength=10, choices='bad')
     
    7979
    8080
    8181error_log = """invalid_models.fielderrors: "charfield": CharFields require a "maxlength" attribute.
    82 invalid_models.fielderrors: "floatfield": FloatFields require a "decimal_places" attribute.
    83 invalid_models.fielderrors: "floatfield": FloatFields require a "max_digits" attribute.
     82invalid_models.fielderrors: "decimalfield": DecimalFields require a "decimal_places" attribute.
     83invalid_models.fielderrors: "decimalfield": DecimalFields require a "max_digits" attribute.
    8484invalid_models.fielderrors: "filefield": FileFields require an "upload_to" attribute.
    8585invalid_models.fielderrors: "prepopulate": prepopulate_from should be a list or tuple.
    8686invalid_models.fielderrors: "choices": "choices" should be iterable (e.g., a tuple or list).
Back to Top