Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#3140 closed defect (duplicate)

"float argument required" exception in admin_list

Reported by: nick@… Owned by: Adrian Holovaty
Component: contrib.admin Version: dev
Severity: normal 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

I get the following exception in the admin app when trying to view a list of objects with a float field in the list_display options:

Exception Type: TypeError
Exception Value: float argument required
Exception Location: /usr/lib/python2.4/site-packages/django/contrib/admin/templatetags/admin_list.py in items_for_result, line 155

However, I don't get this error on my development server which is running SQLite (my "production" server is running MySQL).

The code in question:

152 	            # FloatFields are special: Zero-pad the decimals.
153 	            elif isinstance(f, models.FloatField):
154 	                if field_val is not None:
155 	                    result_repr = ('%%.%sf' % f.decimal_places) % field_val
156 	                else:
157 	                    result_repr = EMPTY_CHANGELIST_VALUE

If I add a float() around the field_val it fixes the problem, e.g.:

152 	            # FloatFields are special: Zero-pad the decimals.
153 	            elif isinstance(f, models.FloatField):
154 	                if field_val is not None:
155 	                    result_repr = ('%%.%sf' % f.decimal_places) % float(field_val)
156 	                else:
157 	                    result_repr = EMPTY_CHANGELIST_VALUE

It looks like the MySQL backend is returning a string for the field_val or something?

Change History (2)

comment:1 by anonymous, 17 years ago

Resolution: duplicate
Status: newclosed

comment:2 by anonymous, 17 years ago

Duplicate of #2917

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