Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.5k views
in Technique[技术] by (71.8m points)

In Django how can we limit a model field to be values 1-10 and increment by whole numbers?

We are trying to create a slider for observed opacity of a sediment filter for a house. 1-10 are the possible values. How could we best accomplish/define this in a Django model. Currently we are using a similar approach with


inline_filter_clarity = models.PositiveSmallIntegerField(
        validators=[MinValueValidator(0), MaxValueValidator(10)])

in models.py and would like to use this in a both a change list and a view, with some limitations:

  1. Limit the values as whole numbers, if possible.
  2. A quick way to have a technician be able to select a value- "slider" is just a criteria suggested from a non-tech team member. We will live with whatever is easiest.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...