Opened 17 years ago
Last modified 13 days ago
#11294 assigned Bug
Django administration Model list always shows Decimal with decimal places
| Reported by: | Owned by: | gaweng | |
|---|---|---|---|
| Component: | contrib.admin | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | tomek@…, gaweng | Triage Stage: | Accepted |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Only in the list_display does the admin interface show DecimalField with precision of .00. In the view of an object in the Model, 0.00, for example, would be shown as 0, without the precision. I'd say the same rendering should be for both, and that displaying without the .00 is preferred.
Change History (9)
comment:1 by , 17 years ago
| milestone: | 1.1 |
|---|
comment:2 by , 17 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:3 by , 15 years ago
| Severity: | → Normal |
|---|---|
| Type: | → Bug |
comment:6 by , 13 years ago
| Version: | 1.1-beta → master |
|---|
The problem here is two folds:
- By default, admin will not localize input values. Not localized input is rendered as
str(value), which isDecimal.__str__. List display usesdisplay_for_field, which localizes value ifUSE_L10Nis true. - When forced to localize (by settings
ModelForm._opts.localized_fields = '__all__'), decimal input still does not honourDecimalField.decimal_placesand is displayed differently from list.
Fix for 2. is easy, overriding _format_value in NumberInput to correctly use number_format with decimal_places.
Fix for 1. is not easy, if not impossible, tickets #13032 and #13546 mention problems with localizing inputs by default. At least we can better document current admin behaviour and include instructions to change it. Better yet, would be to include another ModelAdmin option to control localized_fields in generated ModelForm classes.
comment:7 by , 13 years ago
| Cc: | added |
|---|
comment:8 by , 13 days ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:9 by , 13 days ago
| Cc: | added |
|---|
Issue doesn't exist anymore, cause its handled already in DB Connectors:
SQLite:
# operations.py Line 316-328
def get_decimalfield_converter(self, expression):
if isinstance(expression, Col):
quantize_value = decimal.Decimal(1).scaleb(
-expression.output_field.decimal_places
)
def converter(value, expression, connection):
if value is not None:
return self._create_decimal(value).quantize(
quantize_value, context=expression.output_field.context
)
PostgreSQL:
# base.py Line 93-96
def _get_decimal_column(data):
if data["max_digits"] is None and data["decimal_places"] is None:
return "numeric"
return "numeric(%(max_digits)s, %(decimal_places)s)" % data
MariabDB:
# operations.py Line 28 "DecimalField": "decimal(%(max_digits)s, %(decimal_places)s)",
Not a critical bug, thus not in line for 1.1.