Kaydet (Commit) 27641465 authored tarafından Marc Tamlyn's avatar Marc Tamlyn

Fixed #22838 -- Deprecated ModelChoiceField.cache_choices.

Undocumented, untested and probably not even useful feature.
üst 97adfc2b
...@@ -6,6 +6,7 @@ and database field objects. ...@@ -6,6 +6,7 @@ and database field objects.
from __future__ import unicode_literals from __future__ import unicode_literals
from collections import OrderedDict from collections import OrderedDict
import warnings
from django.core.exceptions import ( from django.core.exceptions import (
ImproperlyConfigured, ValidationError, NON_FIELD_ERRORS, FieldError) ImproperlyConfigured, ValidationError, NON_FIELD_ERRORS, FieldError)
...@@ -16,6 +17,7 @@ from django.forms.utils import ErrorList ...@@ -16,6 +17,7 @@ from django.forms.utils import ErrorList
from django.forms.widgets import (SelectMultiple, HiddenInput, from django.forms.widgets import (SelectMultiple, HiddenInput,
MultipleHiddenInput) MultipleHiddenInput)
from django.utils import six from django.utils import six
from django.utils.deprecation import RemovedInDjango19Warning
from django.utils.encoding import smart_text, force_text from django.utils.encoding import smart_text, force_text
from django.utils.text import get_text_list, capfirst from django.utils.text import get_text_list, capfirst
from django.utils.translation import ugettext_lazy as _, ugettext from django.utils.translation import ugettext_lazy as _, ugettext
...@@ -1092,7 +1094,7 @@ class ModelChoiceField(ChoiceField): ...@@ -1092,7 +1094,7 @@ class ModelChoiceField(ChoiceField):
' the available choices.'), ' the available choices.'),
} }
def __init__(self, queryset, empty_label="---------", cache_choices=False, def __init__(self, queryset, empty_label="---------", cache_choices=None,
required=True, widget=None, label=None, initial=None, required=True, widget=None, label=None, initial=None,
help_text='', to_field_name=None, limit_choices_to=None, help_text='', to_field_name=None, limit_choices_to=None,
*args, **kwargs): *args, **kwargs):
...@@ -1100,6 +1102,12 @@ class ModelChoiceField(ChoiceField): ...@@ -1100,6 +1102,12 @@ class ModelChoiceField(ChoiceField):
self.empty_label = None self.empty_label = None
else: else:
self.empty_label = empty_label self.empty_label = empty_label
if cache_choices is not None:
warnings.warn("cache_choices has been deprecated and will be "
"removed in Django 1.9.",
RemovedInDjango19Warning, stacklevel=2)
else:
cache_choices = False
self.cache_choices = cache_choices self.cache_choices = cache_choices
# Call Field instead of ChoiceField __init__() because we don't need # Call Field instead of ChoiceField __init__() because we don't need
...@@ -1191,7 +1199,7 @@ class ModelMultipleChoiceField(ModelChoiceField): ...@@ -1191,7 +1199,7 @@ class ModelMultipleChoiceField(ModelChoiceField):
'invalid_pk_value': _('"%(pk)s" is not a valid value for a primary key.') 'invalid_pk_value': _('"%(pk)s" is not a valid value for a primary key.')
} }
def __init__(self, queryset, cache_choices=False, required=True, def __init__(self, queryset, cache_choices=None, required=True,
widget=None, label=None, initial=None, widget=None, label=None, initial=None,
help_text='', *args, **kwargs): help_text='', *args, **kwargs):
super(ModelMultipleChoiceField, self).__init__(queryset, None, super(ModelMultipleChoiceField, self).__init__(queryset, None,
......
...@@ -154,6 +154,9 @@ details on these changes. ...@@ -154,6 +154,9 @@ details on these changes.
* Database test settings as independent entries in the database settings, * Database test settings as independent entries in the database settings,
prefixed by ``TEST_``, will no longer be supported. prefixed by ``TEST_``, will no longer be supported.
* The `cache_choices` option to :class:`~django.forms.ModelChoiceField` and
:class:`~django.forms.MultipleModelChoiceField` will be removed.
.. _deprecation-removed-in-1.8: .. _deprecation-removed-in-1.8:
1.8 1.8
......
...@@ -479,3 +479,12 @@ arguments through ``argparse.add_argument()``. See ...@@ -479,3 +479,12 @@ arguments through ``argparse.add_argument()``. See
The class :class:`~django.core.management.NoArgsCommand` is now deprecated and The class :class:`~django.core.management.NoArgsCommand` is now deprecated and
will be removed in Django 2.0. Use :class:`~django.core.management.BaseCommand` will be removed in Django 2.0. Use :class:`~django.core.management.BaseCommand`
instead, which takes no arguments by default. instead, which takes no arguments by default.
``cache_choices`` option of ``ModelChoiceField`` and ``MultipleModelChoiceField``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:class:`~django.forms.ModelChoiceField` and
:class:`~django.forms.MultipleModelChoiceField` took an undocumented, untested
option ``cache_choices``. This cached querysets between multiple renderings of
the same ``Form`` object. This option is subject to an accelerated deprecation
and will be removed in Django 1.9.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment