diff options
| author | Clifford Gama <cliffygamy@gmail.com> | 2025-03-08 15:46:58 +0200 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-03-12 09:16:15 +0100 |
| commit | 0ebea6e5c07485a36862e9b6e2be18d1694ad2c5 (patch) | |
| tree | 6ece342336bea4fbdd74cd29a51d9a071901fc82 /tests/model_forms/models.py | |
| parent | 5183f7c287a9a5d61ca1103b55166cda52d9c647 (diff) | |
Fixed #35676 -- Made BaseModelForm validate constraints that reference an InlineForeignKeyField.
Co-authored-by: Simon Charette <charette.s@gmail.com>
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.", + ), + ] |
