mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
Fixed #3196 -- Fixed inconsistency in setting choices on ChoiceFields dynamically
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4379 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -320,10 +320,19 @@ class ChoiceField(Field):
|
||||
def __init__(self, choices=(), required=True, widget=Select, label=None, initial=None):
|
||||
if isinstance(widget, type):
|
||||
widget = widget()
|
||||
widget.choices = choices
|
||||
super(ChoiceField, self).__init__(required, widget, label, initial)
|
||||
self.choices = choices
|
||||
|
||||
def _get_choices(self):
|
||||
return self._choices
|
||||
|
||||
def _set_choices(self, value):
|
||||
# Setting choices also sets the choices on the widget.
|
||||
self._choices = value
|
||||
self.widget.choices = value
|
||||
|
||||
choices = property(_get_choices, _set_choices)
|
||||
|
||||
def clean(self, value):
|
||||
"""
|
||||
Validates that the input is in self.choices.
|
||||
|
||||
Reference in New Issue
Block a user