Search code examples
pythonpython-3.xdjangomodelnumbers

Django Models Number Field


In Django I'm trying to create a model which will contain a field for player's shirt numbers and was wondering if there is a way to restrict the field to be only numerical inputs. Currently I have in the models.py

number = models.CharField(max_length=2)

Is there a different field to CharField that will allow me to restrict the input to only numbers?


Solution

  • One of the cool things about Django that it provides you with different types of models read about them here.

    For your case try something like this

    number = models.IntegerField()
    

    You can read more about the IntegerField here