File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -306,8 +306,9 @@ def apply(
306306 ):
307307 return
308308 check = f'models.Q({ in_name } =[{ ", " .join ([self ._repr_choice (c ) for c in field_choices ])} ])'
309+ arg_name = "condition" if django .VERSION >= (5 , 1 ) else "check"
309310 yield self .message (
310311 "Field with choices must have companion CheckConstraint to enforce choices on database level." ,
311- hint = f'Add to Meta.constraints: `models.CheckConstraint(name="%(app_label)s_%(class)s_{ field .name } _valid", check ={ check } )`' ,
312+ hint = f'Add to Meta.constraints: `models.CheckConstraint(name="%(app_label)s_%(class)s_{ field .name } _valid", { arg_name } ={ check } )`' ,
312313 obj = field ,
313314 )
Original file line number Diff line number Diff line change @@ -241,16 +241,18 @@ def test_field_choices_constraint(test_case):
241241 "blank_included" ,
242242 "integer_blank_invalid" ,
243243 }
244- assert 'check=models.Q(partial__in=["S", "C"]))' in errors ["partial" ].hint
245- assert "check=models.Q(missed__in=[1, 2]))" in errors ["missed" ].hint
244+ arg_name = "condition" if django .VERSION >= (5 , 1 ) else "check"
245+ assert f'{ arg_name } =models.Q(partial__in=["S", "C"]))' in errors ["partial" ].hint
246+ assert f"{ arg_name } =models.Q(missed__in=[1, 2]))" in errors ["missed" ].hint
246247 assert (
247- 'check=models.Q(blank_missed__in=["A", "B", ""])' in errors ["blank_missed" ].hint
248+ f'{ arg_name } =models.Q(blank_missed__in=["A", "B", ""])'
249+ in errors ["blank_missed" ].hint
248250 )
249251 assert (
250- 'check =models.Q(blank_included__in=["A", "B", ""])'
252+ f' { arg_name } =models.Q(blank_included__in=["A", "B", ""])'
251253 in errors ["blank_included" ].hint
252254 )
253255 assert (
254- "check =models.Q(integer_blank_invalid__in=[1, 2])"
256+ f" { arg_name } =models.Q(integer_blank_invalid__in=[1, 2])"
255257 in errors ["integer_blank_invalid" ].hint
256258 )
You can’t perform that action at this time.
0 commit comments