#19583 closed New feature (wontfix)
FloatFields won't accept locale separators
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.3 |
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
The locale decimal separator is used when generating a template using a floatfield. But if the same value is passed back to the model, it raises an exception: "invalid literal for float()".
This means that a form including <input value="{{mymodel.myfloatfield}}" /> won't work, which seems inconsistent to me.
Change History (6)
comment:1 by , 12 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 12 years ago
Component: | Database layer (models, ORM) → contrib.formtools |
---|---|
Resolution: | invalid |
Status: | closed → new |
Type: | Bug → New feature |
I understand. Then I think Django lacks a tool to validate data without the whole form machinery, e.g. updating just one field through Ajax. I reopen it as a feature request, unless I am not aware of this feature somehow already existing.
comment:3 by , 12 years ago
Component: | contrib.formtools → Database layer (models, ORM) |
---|
You should use forms to validate/sanitize inputs, even if it's just for a single value.
That's what they are made for.
The fact that you're updating a model through Ajax makes no difference at all.
comment:4 by , 12 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
I confirmed what Anssi and Simon said.
The model layer shouldn't know about localization. Otherwise we'll introduce excessive coupling.
comment:5 by , 12 years ago
I'm not sure to understand how to do that. Am I supposed to create one different Form class for every single field I want to update this way?
To me this seems like working as expected.
The localization formats are for input/output between the user and Django. It is supposed that you do input validation/conversions using Django's forms. If not, then you should do input validation by hand, that is you are responsible for converting
POST['myfloatfield']
to Python's accepted float formats.In short, the model layer should not know about the localization formats. The conversions from localized to Python formats should happen in upper layers of the code.