简体   繁体   中英

Set maximum default value for a Django model FloatField

How can I set the maximum value an FloatField can hold in a Django model?

price_upper_bound = models.FloatField(null=True, blank=True, default=0)

Here I want to set maximum float value as a default value for this field. I can set it up manually as any random maximum like 2147483647 ( https://www.postgresql.org/docs/9.1/static/datatype-numeric.html ). Is there any default maximum constant?

This gives you the max float in python:

import sys
sys.float_info.max

More info:

In [1]: import sys

In [2]: sys.float_info
Out[2]: sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM