mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #29641 -- Added support for unique constraints in Meta.constraints.
This constraint is similar to Meta.unique_together but also allows specifying a name. Co-authored-by: Ian Foote <python@ian.feete.org>
This commit is contained in:
committed by
Tim Graham
parent
8eae094638
commit
db13bca60a
@@ -3,8 +3,8 @@ from django.db import models
|
||||
|
||||
class Product(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
price = models.IntegerField()
|
||||
discounted_price = models.IntegerField()
|
||||
price = models.IntegerField(null=True)
|
||||
discounted_price = models.IntegerField(null=True)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
@@ -12,4 +12,5 @@ class Product(models.Model):
|
||||
check=models.Q(price__gt=models.F('discounted_price')),
|
||||
name='price_gt_discounted_price',
|
||||
),
|
||||
models.UniqueConstraint(fields=['name'], name='unique_name'),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user