Django Model Number Field

In Django, I am trying to create a model that will contain a field for shirt numbers for players, and wondered if there is a way to limit the field to only numerical inputs. I currently have in models.py

number = models.CharField(max_length=2) 

Is there another field for CharField that allows me to limit input to numbers only?

+5
source share
2 answers

One of the interesting things about Django that it provides you with various types of models is reading about them here .

In your case, try something like this

 number = models.IntegerField() 

Learn more about IntegerField here.

+8
source

There are several fields in Django, not CharField, either in the case of models or modelfield that you use for forms:

In the case of integers, you use: number = models.IntegerField ()

or even

number = models.FloatField () if you want to present the price of a particular product. It is useful in billing programs.

There is also somemore like BigInteger if you want more nos

Detailed link checking: https://docs.djangoproject.com/en/1.11/ref/models/fields/

0
source

Source: https://habr.com/ru/post/1246765/


All Articles