Skip to content

Commit

Permalink
Add constraints on the enum fields
Browse files Browse the repository at this point in the history
  • Loading branch information
koopmant committed Feb 26, 2025
1 parent 53f7f8e commit 98455f3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 4.2.19 on 2025-02-26 12:41

from django.db import migrations, models

import grandchallenge.invoices.models


class Migration(migrations.Migration):
dependencies = [
("invoices", "0004_alter_invoice_payment_status"),
]

operations = [
migrations.AddConstraint(
model_name="invoice",
constraint=models.CheckConstraint(
check=models.Q(
(
"payment_type__in",
grandchallenge.invoices.models.PaymentTypeChoices,
)
),
name="payment_type_in_choices",
),
),
migrations.AddConstraint(
model_name="invoice",
constraint=models.CheckConstraint(
check=models.Q(
(
"payment_status__in",
grandchallenge.invoices.models.PaymentStatusChoices,
)
),
name="payment_status_in_choices",
),
),
]
12 changes: 12 additions & 0 deletions app/grandchallenge/invoices/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,15 @@ class Invoice(models.Model):
choices=PaymentStatusChoices.choices,
default=PaymentStatusChoices.INITIALIZED,
)

class Meta:
constraints = [
models.CheckConstraint(
check=models.Q(payment_type__in=PaymentTypeChoices),
name="payment_type_in_choices",
),
models.CheckConstraint(
check=models.Q(payment_status__in=PaymentStatusChoices),
name="payment_status_in_choices",
),
]

0 comments on commit 98455f3

Please sign in to comment.