1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +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:
Simon Charette
2018-08-05 22:30:44 -04:00
committed by Tim Graham
parent 8eae094638
commit db13bca60a
7 changed files with 126 additions and 5 deletions

View File

@@ -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'),
]