Ticket #2365: DecimalField.diff
File DecimalField.diff, 11.7 KB (added by , 18 years ago) |
---|
-
django/db/models/fields/__init__.py
617 617 def get_manipulator_field_objs(self): 618 618 return [curry(forms.FilePathField, path=self.path, match=self.match, recursive=self.recursive)] 619 619 620 class FloatField(Field):620 class DecimalField(Field): 621 621 empty_strings_allowed = False 622 622 def __init__(self, verbose_name=None, name=None, max_digits=None, decimal_places=None, **kwargs): 623 623 self.max_digits, self.decimal_places = max_digits, decimal_places 624 624 Field.__init__(self, verbose_name, name, **kwargs) 625 625 626 626 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)] 628 628 629 629 class ImageField(FileField): 630 630 def __init__(self, verbose_name=None, name=None, width_field=None, height_field=None, **kwargs): -
django/db/backends/ado_mssql/creation.py
7 7 'DateTimeField': 'smalldatetime', 8 8 'FileField': 'varchar(100)', 9 9 'FilePathField': 'varchar(100)', 10 ' FloatField':'numeric(%(max_digits)s, %(decimal_places)s)',10 'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)', 11 11 'ImageField': 'varchar(100)', 12 12 'IntegerField': 'int', 13 13 'IPAddressField': 'char(15)', -
django/db/backends/postgresql/introspection.py
80 80 1114: 'DateTimeField', 81 81 1184: 'DateTimeField', 82 82 1266: 'TimeField', 83 1700: ' FloatField',83 1700: 'DecimalField', 84 84 } -
django/db/backends/postgresql/creation.py
11 11 'DateTimeField': 'timestamp with time zone', 12 12 'FileField': 'varchar(100)', 13 13 'FilePathField': 'varchar(100)', 14 ' FloatField':'numeric(%(max_digits)s, %(decimal_places)s)',14 'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)', 15 15 'ImageField': 'varchar(100)', 16 16 'IntegerField': 'integer', 17 17 'IPAddressField': 'inet', -
django/db/backends/sqlite3/creation.py
10 10 'DateTimeField': 'datetime', 11 11 'FileField': 'varchar(100)', 12 12 'FilePathField': 'varchar(100)', 13 ' FloatField':'numeric(%(max_digits)s, %(decimal_places)s)',13 'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)', 14 14 'ImageField': 'varchar(100)', 15 15 'IntegerField': 'integer', 16 16 'IPAddressField': 'char(15)', -
django/db/backends/mysql/introspection.py
76 76 DATA_TYPES_REVERSE = { 77 77 FIELD_TYPE.BLOB: 'TextField', 78 78 FIELD_TYPE.CHAR: 'CharField', 79 FIELD_TYPE.DECIMAL: ' FloatField',79 FIELD_TYPE.DECIMAL: 'DecimalField', 80 80 FIELD_TYPE.DATE: 'DateField', 81 81 FIELD_TYPE.DATETIME: 'DateTimeField', 82 FIELD_TYPE.DOUBLE: ' FloatField',83 FIELD_TYPE.FLOAT: ' FloatField',82 FIELD_TYPE.DOUBLE: 'DecimalField', 83 FIELD_TYPE.FLOAT: 'DecimalField', 84 84 FIELD_TYPE.INT24: 'IntegerField', 85 85 FIELD_TYPE.LONG: 'IntegerField', 86 86 FIELD_TYPE.LONGLONG: 'IntegerField', -
django/db/backends/mysql/creation.py
11 11 'DateTimeField': 'datetime', 12 12 'FileField': 'varchar(100)', 13 13 'FilePathField': 'varchar(100)', 14 ' FloatField':'numeric(%(max_digits)s, %(decimal_places)s)',14 'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)', 15 15 'ImageField': 'varchar(100)', 16 16 'IntegerField': 'integer', 17 17 'IPAddressField': 'char(15)', -
django/db/backends/oracle/introspection.py
48 48 1114: 'DateTimeField', 49 49 1184: 'DateTimeField', 50 50 1266: 'TimeField', 51 1700: ' FloatField',51 1700: 'DecimalField', 52 52 } -
django/db/backends/oracle/creation.py
7 7 'DateTimeField': 'date', 8 8 'FileField': 'varchar2(100)', 9 9 'FilePathField': 'varchar2(100)', 10 ' FloatField':'number(%(max_digits)s, %(decimal_places)s)',10 'DecimalField': 'number(%(max_digits)s, %(decimal_places)s)', 11 11 'ImageField': 'varchar2(100)', 12 12 'IntegerField': 'integer', 13 13 'IPAddressField': 'char(15)', -
django/db/backends/postgresql_psycopg2/introspection.py
80 80 1114: 'DateTimeField', 81 81 1184: 'DateTimeField', 82 82 1266: 'TimeField', 83 1700: ' FloatField',83 1700: 'DecimalField', 84 84 } -
django/forms/__init__.py
736 736 if not 0 <= int(field_data) <= 32767: 737 737 raise validators.CriticalValidationError, gettext("Enter a whole number between 0 and 32,767.") 738 738 739 class FloatField(TextField):739 class DecimalField(TextField): 740 740 def __init__(self, field_name, max_digits, decimal_places, is_required=False, validator_list=None): 741 741 if validator_list is None: validator_list = [] 742 742 self.max_digits, self.decimal_places = max_digits, decimal_places -
django/core/management.py
757 757 if field_type == 'CharField' and row[3]: 758 758 extra_params['maxlength'] = row[3] 759 759 760 if field_type == ' FloatField':760 if field_type == 'DecimalField': 761 761 extra_params['max_digits'] = row[4] 762 762 extra_params['decimal_places'] = row[5] 763 763 … … 831 831 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) 832 832 if isinstance(f, models.CharField) and f.maxlength in (None, 0): 833 833 e.add(opts, '"%s": CharFields require a "maxlength" attribute.' % f.name) 834 if isinstance(f, models. FloatField):834 if isinstance(f, models.DecimalField): 835 835 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) 837 837 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) 839 839 if isinstance(f, models.FileField) and not f.upload_to: 840 840 e.add(opts, '"%s": FileFields require an "upload_to" attribute.' % f.name) 841 841 if isinstance(f, models.ImageField): -
django/contrib/admin/templatetags/admin_list.py
151 151 elif isinstance(f, models.BooleanField) or isinstance(f, models.NullBooleanField): 152 152 BOOLEAN_MAPPING = {True: 'yes', False: 'no', None: 'unknown'} 153 153 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): 156 156 if field_val is not None: 157 157 result_repr = ('%%.%sf' % f.decimal_places) % field_val 158 158 else: -
django/contrib/admin/views/doc.py
297 297 'EmailField' : _('E-mail address'), 298 298 'FileField' : _('File path'), 299 299 'FilePathField' : _('File path'), 300 ' FloatField': _('Decimal number'),300 'DecimalField' : _('Decimal number'), 301 301 'ForeignKey' : _('Integer'), 302 302 'ImageField' : _('File path'), 303 303 'IntegerField' : _('Integer'), -
tests/modeltests/invalid_models/models.py
8 8 9 9 class FieldErrors(models.Model): 10 10 charfield = models.CharField() 11 floatfield = models.FloatField()11 decimalfield = models.DecimalField() 12 12 filefield = models.FileField() 13 13 prepopulate = models.CharField(maxlength=10, prepopulate_from='bad') 14 14 choices = models.CharField(maxlength=10, choices='bad') … … 79 79 80 80 81 81 error_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.82 invalid_models.fielderrors: "decimalfield": DecimalFields require a "decimal_places" attribute. 83 invalid_models.fielderrors: "decimalfield": DecimalFields require a "max_digits" attribute. 84 84 invalid_models.fielderrors: "filefield": FileFields require an "upload_to" attribute. 85 85 invalid_models.fielderrors: "prepopulate": prepopulate_from should be a list or tuple. 86 86 invalid_models.fielderrors: "choices": "choices" should be iterable (e.g., a tuple or list).