From 2764146586509c2c81ad14da4ac86efa3a949308 Mon Sep 17 00:00:00 2001 From: Marc Tamlyn Date: Sun, 15 Jun 2014 12:02:39 +0100 Subject: [PATCH] Fixed #22838 -- Deprecated ModelChoiceField.cache_choices. Undocumented, untested and probably not even useful feature. --- django/forms/models.py | 12 ++++++++++-- docs/internals/deprecation.txt | 3 +++ docs/releases/1.8.txt | 9 +++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/django/forms/models.py b/django/forms/models.py index 055af3cf77..9e6cab8c84 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -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, diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index 39c42ae7bf..54ca279ff1 100644 --- a/docs/internals/deprecation.txt +++ b/docs/internals/deprecation.txt @@ -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 diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt index b406c661fe..2351e96c18 100644 --- a/docs/releases/1.8.txt +++ b/docs/releases/1.8.txt @@ -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.