FloatField not converting values to float()
|Reported by:||pjrobertson||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.7-rc-2|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Description (last modified by bmispelon)
Apologies for creating an issue if this is the expected behaviour (FWIW there were no ideas on IRC):
Is the behaviour outlined in this snippet expected:
# models.py from django.db import models class Fl(models.Model): float = models.FloatField() # ./manage.py shell >>> from models import Fl >>> a = Fl.objects.create(float=' 1.0 ') >>> a <Fl: Fl object> >>> a.float ' 1.0 '
I'd have expected the FloatField to convert values to a float in the return object as well (I can verify that the to_python method is being run, because the number is saved to the database correctly.
Is the recommended way of solving this to subclass FloatField and use?
class MyFloatField(with_metaclass(models.SubBaseField, models.FloadField)): ...
Change History (3)
comment:1 Changed 18 months ago by collinanderson
- Cc cmawebsite@… added
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Type changed from Uncategorized to Cleanup/optimization