How to compare two fields in a CheckConstraint

Viewed 1310

If this is my model:

class Bid(models.Model):

    amount = models.DecimalField(max_digits=11, decimal_places=2)
    starting_bid = models.DecimalField(max_digits=11, decimal_places=2, null=True)

How do I add a constraint that checks if the amount field is greater than or equal to the starting bid? This is what I have now:

class Meta:
    constraints = [
        models.CheckConstraint(check=Q(amount > starting_bid), name='amount_gte_starting_bid')
    ]

Which of course is not correct. Thank you!

1 Answers
Related