﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31084	ValueError: could not convert string to float.	Sevdimali	nobody	"Hi,
**I have a field like this(models.py):**

{{{
value = models.FloatField(null=True)
}}}

**And I have a simple form (template/form.html)**

{{{
 <form action=""{% url 'submit_form' %}"" method=""post"">
    {% csrf_token %}
    <input type=""hidden"" name=""star"" value="""">
    <input type=""submit"">
</form>
}}}

**in my view, I am saving this form (views.py) :**


{{{
 def submit_form(request):
    if request.method == ""POST"":
        print(""aa"")
        score = request.POST.get('star')
       
        simpleform.objects.create(
            value=score,
        )
    return redirect(""/form"")
}}}

**and of course, I am getting this exception:**

{{{
ValueError: could not convert string to float:
}}}
 
**Adding if statement something like this to view will solve the exception:**
     
{{{
   if len(score) == 0:
            score = None
}}}

**I am thinking that maybe we can add this check to our  site-packages/django/db/fields/__init.py__**

{{{
    def get_prep_value(self, value):
        value = super().get_prep_value(value)
        if value is None:
            return None
        return float(value)
}}}
to
   
{{{
 def get_prep_value(self, value):
        value = super().get_prep_value(value)
        if value is None or len(value) == 0:
            return None
        return float(value)
}}}
"	Cleanup/optimization	closed	Database layer (models, ORM)	2.2	Normal	invalid			Unreviewed	0	0	0	0	0	0
