diff --git a/example/example/app/models.py b/example/example/app/models.py index e4f6504..a0a915a 100644 --- a/example/example/app/models.py +++ b/example/example/app/models.py @@ -42,7 +42,9 @@ TAGS_CHOICES = ( class Book(models.Model): title = models.CharField(max_length=200) categories = MultiSelectField(choices=CATEGORY_CHOICES, - max_choices=3) + max_choices=3, + #default='1,5', + default=1) tags = MultiSelectField(choices=TAGS_CHOICES, null=True, blank=True) diff --git a/src/multiselectfield/db/fields.py b/src/multiselectfield/db/fields.py index 6a39f5e..ba19a27 100644 --- a/src/multiselectfield/db/fields.py +++ b/src/multiselectfield/db/fields.py @@ -82,7 +82,12 @@ class MultiSelectField(models.CharField): raise exceptions.ValidationError(self.error_messages['invalid_choice'] % {"value": value}) else: raise exceptions.ValidationError(self.error_messages['invalid_choice'] % value) - return + + def get_default(self): + default = super(MultiSelectField, self).get_default() + if isinstance(default, int): + default = string_type(default) + return default def formfield(self, **kwargs): defaults = {'required': not self.blank,