Allow only positive decimal numbers

前端 未结 5 1196
北海茫月
北海茫月 2021-02-01 13:48

Within my Django models I have created a decimal field like this:

price = models.DecimalField(_(u\'Price\'), decimal_places=2, max_digits=12)

O

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-01 14:21

    You could do something like this :

    # .....
    class priceForm(ModelForm):
        price = forms.DecimalField(required=False, max_digits=6, min_value=0)
    

    This, also, is responsible for the validator value of 'price'.

提交回复
热议问题