From 1c0a31267d489976ce12872342c2852e8ce12375 Mon Sep 17 00:00:00 2001 From: Kumi Date: Wed, 7 Sep 2022 15:58:06 +0000 Subject: [PATCH] Make compatible with Django 4.1 (hopefully) --- multiselectfield/db/fields.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/multiselectfield/db/fields.py b/multiselectfield/db/fields.py index 7d4eef6..a11702b 100644 --- a/multiselectfield/db/fields.py +++ b/multiselectfield/db/fields.py @@ -54,7 +54,13 @@ class MultiSelectField(models.CharField): self.max_choices = kwargs.pop('max_choices', None) super(MultiSelectField, self).__init__(*args, **kwargs) self.max_length = get_max_length(self.choices, self.max_length) - self.validators[0] = MaxValueMultiFieldValidator(self.max_length) + + validator = MaxValueMultiFieldValidator(self.max_length) + if not self.validators: + self.validators.append(validator) + else: + self.validators[0] = validator + if self.min_choices is not None: self.validators.append(MinChoicesValidator(self.min_choices)) if self.max_choices is not None: