mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #22838 -- Deprecated ModelChoiceField.cache_choices.
Undocumented, untested and probably not even useful feature.
This commit is contained in:
		| @@ -6,6 +6,7 @@ and database field objects. | ||||
| from __future__ import unicode_literals | ||||
|  | ||||
| from collections import OrderedDict | ||||
| import warnings | ||||
|  | ||||
| from django.core.exceptions import ( | ||||
|     ImproperlyConfigured, ValidationError, NON_FIELD_ERRORS, FieldError) | ||||
| @@ -16,6 +17,7 @@ from django.forms.utils import ErrorList | ||||
| from django.forms.widgets import (SelectMultiple, HiddenInput, | ||||
|     MultipleHiddenInput) | ||||
| from django.utils import six | ||||
| from django.utils.deprecation import RemovedInDjango19Warning | ||||
| from django.utils.encoding import smart_text, force_text | ||||
| from django.utils.text import get_text_list, capfirst | ||||
| from django.utils.translation import ugettext_lazy as _, ugettext | ||||
| @@ -1092,7 +1094,7 @@ class ModelChoiceField(ChoiceField): | ||||
|                             ' 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, | ||||
|                  help_text='', to_field_name=None, limit_choices_to=None, | ||||
|                  *args, **kwargs): | ||||
| @@ -1100,6 +1102,12 @@ class ModelChoiceField(ChoiceField): | ||||
|             self.empty_label = None | ||||
|         else: | ||||
|             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 | ||||
|  | ||||
|         # Call Field instead of ChoiceField __init__() because we don't need | ||||
| @@ -1191,7 +1199,7 @@ class ModelMultipleChoiceField(ModelChoiceField): | ||||
|         '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, | ||||
|                  help_text='', *args, **kwargs): | ||||
|         super(ModelMultipleChoiceField, self).__init__(queryset, None, | ||||
|   | ||||
| @@ -154,6 +154,9 @@ details on these changes. | ||||
| * Database test settings as independent entries in the database settings, | ||||
|   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: | ||||
|  | ||||
| 1.8 | ||||
|   | ||||
| @@ -479,3 +479,12 @@ arguments through ``argparse.add_argument()``. See | ||||
| The class :class:`~django.core.management.NoArgsCommand` is now deprecated and | ||||
| will be removed in Django 2.0. Use :class:`~django.core.management.BaseCommand` | ||||
| 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. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user