How can I have check constraint in django which check two fields of related models?

from django.db import models
from djago.db.models import F, Q

class(models.Model):
    order_date = models.DateField()
    
class OrderLine(models.Model):
    order = models.ForeignKeyField(Order)
    loading_date = models.DateField()
    
    class Meta:

        constraints = [
        models.CheckConstraint(check=Q(loading_date__gte=F("order__order_date")), name="disallow_backdated_loading")

I want to make sure always orderline loading_date is higher than orderdate



from Recent Questions - Stack Overflow https://ift.tt/3A72VNv
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations