Yes, using things like models.F('price') made it !
Thank you very much, Leonardo, for this.
Le mercredi 13 novembre 2019 13:35:37 UTC+1, LRezende a écrit :
>
> 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]
> <javascript:>> 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] <javascript:>.
>> 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/ce19686c-8a3b-4d29-bc81-33137560737a%40googlegroups.com.