Hi,
Didn't tested... Did you try the F expression?
from django.db import models
class Customer(models.Model):
age = models.IntegerField()
class Meta:
constraints = [
models.CheckConstraint(check=models.Q(discounted_price__lte=models.F('price')),
name='age_gte_18'),
]
Em ter., 12 de nov. de 2019 às 14:14, Olivier <[email protected]> escreveu:
> hello,
>
> Looking at [1], I can see examples where one can check at database level,
> that a model field min_foo satisfies a constraint such as "min_foo > 5".
> How do you write a constraint involving two different fields like
> "min_foo < max_foo" or "discounted_price < price" ?
>
> PostgreSQL doc shows how to write such constraint but how to express those
> with Django 2.2 ?
>
> [1] https://docs.djangoproject.com/en/2.2/ref/models/constraints/
>
> Best regards
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/43d1b1aa-9261-4ebc-b54f-761959c01c31%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/43d1b1aa-9261-4ebc-b54f-761959c01c31%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
--
Leonardo Rezende
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAJ%2BpOBuysxokZfqCE%3D%2BFw23UM6TBDMdDvcoKksyABturE7Ej%2Bg%40mail.gmail.com.