Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#2917 closed defect (fixed)

[PATCH] Admin list display doesn't properly display FloatFields

Reported by: heckj@… Owned by: Adrian Holovaty
Component: contrib.admin Version: master
Severity: major Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


In version 0.95 and through trunk on SVN, the admin interface by default doesn't properly display values stored in FloatFields.

The resulting access to the admin page with a FloatField results in the traceback:

If you use a FloatField in the admin list_display, you get an error
rendering the template from line 160 in (TypeError, float
argument required)

  1. elif isinstance(f, models.FloatField):
  2. if field_val is not None:
  3. result_repr = ('%%.%sf' % f.decimal_places) %


  1. else:
  2. result_repr = EMPTY_CHANGELIST_VALUE

Back in April, Dave A recorded a possible fix on the django-user's mailing list, but I wasn't ever able to find a bug about it, or a patch - so I'm supplying it based on what he suggested. It works nicely, and resolves the internal display issue. He asserted:

I think the line should be:

  1. result_repr = ('%%.%df' % f.decimal_places) % float(field_val)

Attachments (1)

admin_float_field.diff (770 bytes) - added by heckj@… 12 years ago.
Patch file for admin list display

Download all attachments as: .zip

Change History (5)

Changed 12 years ago by heckj@…

Attachment: admin_float_field.diff added

Patch file for admin list display

comment:1 Changed 12 years ago by Matt McClanahan <cardinal@…>

Resolution: fixed
Status: newclosed

This appears to be functioning normally in trunk. Can you retest?

comment:2 Changed 12 years ago by nick@…

I still have the same problem, but it's only happening when I use the MySQL backend - don't have the error with the SQLite backend. I'm using trunk also but a couple of weeks old since I can't access the SVN from work due to proxy issues - will update and retest but it looks like the code hasn't changed since my last update.

P.S. Sorry about the duplicate ticket, in a rush and thought I had already checked but obviously not.

comment:3 Changed 12 years ago by nick@…

Just found #1364, looks like I have to update MySQL python bindings. Sorry about the confusion, ignore previous post.

comment:4 Changed 11 years ago by Michal Chruszcz <troll@…>

I think that including this tiny patch wouldn't bother anyone, while updating MySQL driver might be a struggling task (e.g. when you, just like me, use a shared hosting and don't have much influence on the versions of software installed). Why not to apply it to the trunk?

Note: See TracTickets for help on using tickets.
Back to Top