34👍
3👍
Player’s shirt numbers should need only positive numbers.
PositiveBigIntegerField allows values from 0 to 9223372036854775807:
number = models.PositiveBigIntegerField()
PositiveIntegerField allows values from 0 to 2147483647:
number = models.PositiveIntegerField()
PositiveSmallIntegerField allows values from 0 to 32767:
number = models.PositiveSmallIntegerField()
In addition, there are no "NegativeIntegerField", "NegativeBigIntegerField" and "NegativeSmallIntegerField" in Django.
- ALLOWED_HOSTS and Django
- Django testing: Got an error creating the test database: database "database_name" already exists
- How to paginate "Change List" page in Django admin?
- How to get user email with python social auth with facebook and save it
- How to disable HTML encoding when using Context in django
0👍
There a number of fields rather than CharField in Django either in case of models or modelfields you use for forms:
In case of Integers you use: number = models.IntegerField()
or even
number = models.FloatField(), in case you want to represent price of a specific commodity.Its usefull in billing softwares.
There is also somemore like BigInteger field in case you wanted more nos
For detailed reference check:https://docs.djangoproject.com/en/1.11/ref/models/fields/
- UUID field added after data already in database. Is there any way to populate the UUID field for existing data?
- Inlineformset_factory create new objects and edit objects after created
0👍
If you’re using serializers, you can use validators for these cases. For example, for a 10-digit CharField, you can have a validator like this :
def postalcode_validator(value):
rule = re.compile(r'^\d{10}$')
if not rule.search(value):
raise serializers.ValidationError("Postal code format must be XXXXXXXXXX")
return value
Then, you can use this validator with your serializer’s CharField:
# serializers.py
...
postal_code = serializers.CharField(validators=[postalcode_validator])
Moreover, validators can be used with model fields as well just like the above example.
- TypeError: __call__() missing 1 required positional argument: 'send' Django
- How to add some extra fields to the page in django-cms? (in django admin panel)