Skip to content

Commit

Permalink
Update model_field_checks.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn authored Dec 9, 2024
1 parent a4b241c commit 91e69b3
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/extra_checks/checks/model_field_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,9 @@ def apply(
):
return
check = f'models.Q({in_name}=[{", ".join([self._repr_choice(c) for c in field_choices])}])'
arg_name = "condition" if django.VERSION >= (5, 1) else "check"
yield self.message(
"Field with choices must have companion CheckConstraint to enforce choices on database level.",
hint=f'Add to Meta.constraints: `models.CheckConstraint(name="%(app_label)s_%(class)s_{field.name}_valid", condition={check})`',
hint=f'Add to Meta.constraints: `models.CheckConstraint(name="%(app_label)s_%(class)s_{field.name}_valid", {arg_name}={check})`',
obj=field,
)

0 comments on commit 91e69b3

Please sign in to comment.