1π
β
You have a few problems here.
Firstly, you are using the values directly from request.POST
. Those will always be strings. To get the values in the type specified in your form, you should use the form.cleaned_data
dict.
Secondly, your fields are decimals, but your arrays contain floats. Due to floating-point imprecision, 29.1
for example is not the same as decimal.Decimal("29.1")
. You should use consistent types; Decimal is probably the most appropriate here.
Thirdly, this isnβt really the best way to do it. It would be much easier to use comparisons:
if Decimal("29.0") <= chest < Decimal("32.0"):
...
elif Decimal("32.0") <= chest < Decimal("33.5"):
...
and so on.
π€Daniel Roseman
0π
You are setting chest
from request.POST
which will give you a string value. Convert it to a float
and it should work.
π€Jody Boucher
- Python3: Loop over objects and add attributes to an array or object
- Is it possible to build a homepage with python on virtual server when the sudo command is disabled?
- When i upgrade django-debug-toolbar at 1.6 is does not working
- What is the best way of saving related model in django admin?
Source:stackexchange.com