2

I am trying to make price field that has a maximum value. But I have seen that it is not possible to specify max value in models decimal field. Therefor I created a form decimal field which takes max value attribute but if do that I am not able to use the model's price field's properties. In models.py

 price = models.DecimalField(max_digits=5, decimal_places=2)

In forms.py

 price = forms.DecimalField(max_value=500)

I know I can just write all of them in forms and leave the blank and null in model's decimal field but doing that is redundant as I have many other fields.

Is there a way I can use the model's decimal field and still specify the max length and min length for that field through forms class.

vikram
  • 361
  • 5
  • 15
  • Check this out: [https://stackoverflow.com/questions/849142/how-to-limit-the-maximum-value-of-a-numeric-field-in-a-django-model][1] – Lakshitha Wisumperuma Mar 05 '19 at 05:14
  • max_value can be used in forms as of now. So you can give an error message when the value exceeds. I did not understand this `if do that I am not able to use the model's price field's properties`. Can you share your forms. – Bidhan Majhi Mar 05 '19 at 06:54

0 Answers0