Skip to content

Commit b12159d

Browse files
authored
Support Django 5.1+ syntax for CheckConstraint condition
1 parent c26bfc5 commit b12159d

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

django_tasks/backends/database/models.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import uuid
33
from typing import TYPE_CHECKING, Any, Generic, Optional, TypeVar
44

5+
import django
56
from django.core.exceptions import SuspiciousOperation
67
from django.db import models
78
from django.db.models import F, Q
@@ -108,12 +109,21 @@ class Meta:
108109
ordering = [F("priority").desc(), F("run_after").desc(nulls_last=True)]
109110
verbose_name = _("Task Result")
110111
verbose_name_plural = _("Task Results")
111-
constraints = [
112-
CheckConstraint(
113-
check=Q(priority__range=(MIN_PRIORITY, MAX_PRIORITY)),
114-
name="priority_range",
115-
)
116-
]
112+
113+
if django.VERSION >= (5, 1):
114+
constraints = [
115+
CheckConstraint(
116+
condition=Q(priority__range=(MIN_PRIORITY, MAX_PRIORITY)), # type: ignore
117+
name="priority_range",
118+
)
119+
]
120+
else:
121+
constraints = [
122+
CheckConstraint(
123+
check=Q(priority__range=(MIN_PRIORITY, MAX_PRIORITY)),
124+
name="priority_range",
125+
)
126+
]
117127

118128
@property
119129
def task(self) -> Task[P, T]:

0 commit comments

Comments
 (0)