Monday, November 24, 2014

Re: DecimalField returns 'This value must be a decimal number' when blank

Hi,

Use form.cleaned_data instead of request.POST, because form.cleaned_data will property convert strings into decimals or None.

codpozo = form.cleaned_data['codpozo']

But again, use a ModelForm. it's super easy:

class PozoForm(forms.ModelForm):
   
class Meta:
        model
= Pozo
        fields
= '__all__'

def EdicionCuenca(request):
   
if 'pozoform' in request.POST:
        pozoform
= PozoForm(request.POST)
        if pozoform.is_valid():
            pozo
= PosoForm.save()
           
return redirect('/edicioncuenca/')
   
else:
        pozoform
= PozoForm()
   
# etc

Collin

On Saturday, November 22, 2014 12:57:13 PM UTC-5, elcaiaimar wrote:
Hi Collin

I'm using postgresql db, I' ve attached my views, forms and models. I' ve thought to do the ModelForm when I solve this problem, thanks for your advice!

Thank you very much!


El domingo, 16 de noviembre de 2014 18:51:43 UTC+1, elcaiaimar escribió:
Hello everybody, I've a problem with DecimalField at Forms. I've a long form in my template and I want to left some fields in blank. I've declared these fields with
required=False, but when I submit the form I receive this error: 'This value must be a decimal number'.

I've tried to declare blank=True, null=True in respective fields in models.py and make a syncdb but it continues without works

Does somebody know how could I solve this problem?

Thank you very much!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/35c538f7-c3a2-424c-bb0a-1fed7921abb3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment