Improvements in the default value
This commit is contained in:
parent
6463dfd0f6
commit
075950197a
|
@ -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)
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue