Opened 18 years ago

Closed 18 years ago

Last modified 17 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: dev
Severity: major Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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 admin_list.py (TypeError, float
argument required)

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

field_val

  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@… 18 years ago.
Patch file for admin list display

Download all attachments as: .zip

Change History (5)

by heckj@…, 18 years ago

Attachment: admin_float_field.diff added

Patch file for admin list display

comment:1 by Matt McClanahan <cardinal@…>, 18 years ago

Resolution: fixed
Status: newclosed

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

comment:2 by nick@…, 18 years ago

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 by nick@…, 18 years ago

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

comment:4 by Michal Chruszcz <troll@…>, 17 years ago

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