diff options
Diffstat (limited to 'tests/model_forms/models.py')
| -rw-r--r-- | tests/model_forms/models.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/model_forms/models.py b/tests/model_forms/models.py index f9441a4c77..4111fafd69 100644 --- a/tests/model_forms/models.py +++ b/tests/model_forms/models.py @@ -521,3 +521,24 @@ class Dice(models.Model): through=NumbersToDice, limit_choices_to=models.Q(value__gte=1), ) + + +class ConstraintsModel(models.Model): + name = models.CharField(max_length=100) + category = models.CharField(max_length=50, default="uncategorized") + price = models.DecimalField(max_digits=10, decimal_places=2, default=0) + + class Meta: + constraints = [ + models.UniqueConstraint( + "name", + "category", + name="unique_name_category", + violation_error_message="This product already exists.", + ), + models.CheckConstraint( + condition=models.Q(price__gt=0), + name="price_gte_zero", + violation_error_message="Price must be greater than zero.", + ), + ] |
