I have a django model,
class MyModel(models.Model)
qty = model.IntegerField()
where I want to set constraint for qty
somet
You will have to create a custom validator
from django.core.exceptions import ValidationError
def validate_number(value):
if something : # Your conditions here
raise ValidationError('%s some error message' % value)
And then use this validator in your model
from django.db import models
class MyModel(models.Model):
field = models.IntegerField(validators=[validate_number])