2016-11-05 21:12:12 +08:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
|
|
|
|
class Product(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
2018-08-06 10:30:44 +08:00
|
|
|
price = models.IntegerField(null=True)
|
|
|
|
discounted_price = models.IntegerField(null=True)
|
2016-11-05 21:12:12 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
constraints = [
|
|
|
|
models.CheckConstraint(
|
2018-08-06 10:15:10 +08:00
|
|
|
check=models.Q(price__gt=models.F('discounted_price')),
|
|
|
|
name='price_gt_discounted_price',
|
|
|
|
),
|
2018-08-06 10:30:44 +08:00
|
|
|
models.UniqueConstraint(fields=['name'], name='unique_name'),
|
2016-11-05 21:12:12 +08:00
|
|
|
]
|