mirror of https://github.com/django/django.git
Removed Multiple/ModelChoiceField cache_choices option; refs #22838.
This commit is contained in:
parent
4b8d3bbab5
commit
2788c46d46
|
@ -1078,16 +1078,8 @@ class ModelChoiceIterator(object):
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
if self.field.empty_label is not None:
|
if self.field.empty_label is not None:
|
||||||
yield ("", self.field.empty_label)
|
yield ("", self.field.empty_label)
|
||||||
if self.field.cache_choices:
|
for obj in self.queryset.iterator():
|
||||||
if self.field.choice_cache is None:
|
yield self.choice(obj)
|
||||||
self.field.choice_cache = [
|
|
||||||
self.choice(obj) for obj in self.queryset.iterator()
|
|
||||||
]
|
|
||||||
for choice in self.field.choice_cache:
|
|
||||||
yield choice
|
|
||||||
else:
|
|
||||||
for obj in self.queryset.iterator():
|
|
||||||
yield self.choice(obj)
|
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return (len(self.queryset) +
|
return (len(self.queryset) +
|
||||||
|
@ -1106,7 +1098,7 @@ class ModelChoiceField(ChoiceField):
|
||||||
' the available choices.'),
|
' the available choices.'),
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, queryset, empty_label="---------", cache_choices=None,
|
def __init__(self, queryset, empty_label="---------",
|
||||||
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):
|
||||||
|
@ -1114,13 +1106,6 @@ 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
|
|
||||||
|
|
||||||
# Call Field instead of ChoiceField __init__() because we don't need
|
# Call Field instead of ChoiceField __init__() because we don't need
|
||||||
# ChoiceField.__init__().
|
# ChoiceField.__init__().
|
||||||
|
@ -1128,7 +1113,6 @@ class ModelChoiceField(ChoiceField):
|
||||||
*args, **kwargs)
|
*args, **kwargs)
|
||||||
self.queryset = queryset
|
self.queryset = queryset
|
||||||
self.limit_choices_to = limit_choices_to # limit the queryset later.
|
self.limit_choices_to = limit_choices_to # limit the queryset later.
|
||||||
self.choice_cache = None
|
|
||||||
self.to_field_name = to_field_name
|
self.to_field_name = to_field_name
|
||||||
|
|
||||||
def get_limit_choices_to(self):
|
def get_limit_choices_to(self):
|
||||||
|
@ -1222,12 +1206,10 @@ 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=None, required=True,
|
def __init__(self, queryset, required=True, widget=None, label=None,
|
||||||
widget=None, label=None, initial=None,
|
initial=None, help_text='', *args, **kwargs):
|
||||||
help_text='', *args, **kwargs):
|
|
||||||
super(ModelMultipleChoiceField, self).__init__(queryset, None,
|
super(ModelMultipleChoiceField, self).__init__(queryset, None,
|
||||||
cache_choices, required, widget, label, initial, help_text,
|
required, widget, label, initial, help_text, *args, **kwargs)
|
||||||
*args, **kwargs)
|
|
||||||
|
|
||||||
def to_python(self, value):
|
def to_python(self, value):
|
||||||
if not value:
|
if not value:
|
||||||
|
|
Loading…
Reference in New Issue