1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #6967: ModelForms now validate choices. Thanks, mattmcc -- the failing test helped quite a bit.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8772 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss
2008-08-31 20:11:11 +00:00
parent 4ae746b574
commit 3b63953704
2 changed files with 36 additions and 1 deletions

View File

@@ -305,7 +305,13 @@ class Field(object):
"Returns a django.forms.Field instance for this database Field."
defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
if self.choices:
defaults['widget'] = forms.Select(choices=self.get_choices(include_blank=self.blank or not (self.has_default() or 'initial' in kwargs)))
form_class = forms.TypedChoiceField
include_blank = self.blank or not (self.has_default() or 'initial' in kwargs)
defaults['choices'] = self.get_choices(include_blank=include_blank)
defaults['coerce'] = self.to_python
if self.null:
defaults['empty_value'] = None
kwargs.pop('max_length', None)
if self.has_default():
defaults['initial'] = self.get_default()
defaults.update(kwargs)