From 075950197a5f7910486d8825fff998ef7c4db0a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Mart=C3=ADn?= Date: Sat, 30 Nov 2013 19:25:11 +0100 Subject: [PATCH] Improvements in the default value --- example/example/app/models.py | 4 +++- src/multiselectfield/db/fields.py | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) 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,