Wednesday, November 13, 2019

Re: Django 2.2 CheckContraint: how to check "min_foo < max_foo" ?

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 <oza.4h07@gmail.com> 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 ?


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 django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/43d1b1aa-9261-4ebc-b54f-761959c01c31%40googlegroups.com.


--
--

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 django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJ%2BpOBuysxokZfqCE%3D%2BFw23UM6TBDMdDvcoKksyABturE7Ej%2Bg%40mail.gmail.com.

No comments:

Post a Comment