Skip to content Skip to sidebar Skip to footer

Django Validation Error U"'' Value Must Be A Decimal Number."

I am trying to get data from a form, the form is reproduced a number of times based on a list. One form for each item. The form consists of a checkbox and a textfield. If the check

Solution 1:

There are empty prices in the list, skip them. Also, cast strings to decimals:

from decimal import Decimal

...

for price in request.POST.getlist('price'):
    if not price:
        continue
    list_item.price = Decimal(price)
    list_item.save()

Post a Comment for "Django Validation Error U"'' Value Must Be A Decimal Number.""