Code

Opened 5 years ago

Last modified 13 months ago

#11294 new Bug

Django administration Model list always shows Decimal with decimal places

Reported by: jason@… Owned by: nobody
Component: contrib.admin Version: master
Severity: Normal Keywords:
Cc: tomek@… 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.

Attachments (0)

Change History (7)

comment:1 Changed 5 years ago by Alex

  • milestone 1.1 deleted
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Not a critical bug, thus not in line for 1.1.

comment:2 Changed 5 years ago by Alex

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 3 years ago by julien

  • Severity set to Normal
  • Type set to Bug

comment:4 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:5 Changed 2 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:6 Changed 13 months ago by oinopion

  • Version changed from 1.1-beta to master

The problem here is two folds:

  1. By default, admin will not localize input values. Not localized input is rendered as str(value), which is Decimal.__str__. List display uses display_for_field, which localizes value if USE_L10N is true.
  2. When forced to localize (by settings ModelForm._opts.localized_fields = '__all__'), decimal input still does not honour DecimalField.decimal_places and 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.

Last edited 13 months ago by oinopion (previous) (diff)

comment:7 Changed 13 months ago by oinopion

  • Cc tomek@… added

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from nobody to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.