Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#19583 closed New feature (wontfix)

FloatFields won't accept locale separators

Reported by: sylvain.lebon@… 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 Anssi Kääriäinen, 11 years ago

Resolution: invalid
Status: newclosed

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.

comment:2 by anonymous, 11 years ago

Component: Database layer (models, ORM)contrib.formtools
Resolution: invalid
Status: closednew
Type: BugNew 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 Simon Charette, 11 years ago

Component: contrib.formtoolsDatabase 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 Aymeric Augustin, 11 years ago

Resolution: wontfix
Status: newclosed

I confirmed what Anssi and Simon said.

The model layer shouldn't know about localization. Otherwise we'll introduce excessive coupling.

comment:5 by anonymous, 11 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?

comment:6 by libraM@…, 10 years ago

For Django >= 1.6, comment:4:ticket:18509 may help.

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