From c7291fd0afe7c6b42f205a44f84b97151abf9a52 Mon Sep 17 00:00:00 2001
From: Sebastian Noack <sebastian.noack@gmail.com>
Date: Thu, 15 May 2008 16:18:23 +0200
Subject: [PATCH] Fixed widget handling in ModelChoicesField.__init__ and ModelMultipleChoicesField.__init__ (#7244).
---
django/newforms/models.py | 16 +++++++++++-----
1 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/django/newforms/models.py b/django/newforms/models.py
index 78a2041..d6451ee 100644
a
|
b
|
from django.core.exceptions import ImproperlyConfigured
|
13 | 13 | from util import ValidationError, ErrorList |
14 | 14 | from forms import BaseForm, get_declared_fields |
15 | 15 | from fields import Field, ChoiceField, EMPTY_VALUES |
16 | | from widgets import Select, SelectMultiple, MultipleHiddenInput |
| 16 | from widgets import MultipleHiddenInput |
17 | 17 | |
18 | 18 | __all__ = ( |
19 | 19 | 'ModelForm', 'BaseModelForm', 'model_to_dict', 'fields_for_model', |
… |
… |
class ModelChoiceField(ChoiceField):
|
301 | 301 | } |
302 | 302 | |
303 | 303 | def __init__(self, queryset, empty_label=u"---------", cache_choices=False, |
304 | | required=True, widget=Select, label=None, initial=None, |
| 304 | required=True, widget=None, label=None, initial=None, |
305 | 305 | help_text=None, *args, **kwargs): |
306 | 306 | self.empty_label = empty_label |
307 | 307 | self.cache_choices = cache_choices |
… |
… |
class ModelChoiceField(ChoiceField):
|
346 | 346 | # the queryset. |
347 | 347 | return ModelChoiceIterator(self) |
348 | 348 | |
349 | | choices = property(_get_choices, ChoiceField._set_choices) |
| 349 | def _set_choices(self, value): |
| 350 | # This method is copied from ChoiceField._set_choices(). It's necessary |
| 351 | # because property() doesn't allow a subclass to overwrite only |
| 352 | # _get_choices without implementing _set_choices. |
| 353 | self._choices = self.widget.choices = list(value) |
| 354 | |
| 355 | choices = property(_get_choices, _set_choices) |
350 | 356 | |
351 | 357 | def clean(self, value): |
352 | 358 | Field.clean(self, value) |
… |
… |
class ModelMultipleChoiceField(ModelChoiceField):
|
368 | 374 | } |
369 | 375 | |
370 | 376 | def __init__(self, queryset, cache_choices=False, required=True, |
371 | | widget=SelectMultiple, label=None, initial=None, |
372 | | help_text=None, *args, **kwargs): |
| 377 | widget=None, label=None, initial=None, help_text=None, |
| 378 | *args, **kwargs): |
373 | 379 | super(ModelMultipleChoiceField, self).__init__(queryset, None, |
374 | 380 | cache_choices, required, widget, label, initial, help_text, |
375 | 381 | *args, **kwargs) |