From 901dc90db0d95ddcd9a7d9608c8158cb9dbd824c Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Thu, 14 Apr 2016 21:09:09 -0400 Subject: [PATCH] Removed unused/untested Field.get_choices_default()/value_to_string() methods. --- django/contrib/contenttypes/fields.py | 3 --- django/db/models/fields/__init__.py | 3 --- django/db/models/fields/related.py | 31 +-------------------------- 3 files changed, 1 insertion(+), 36 deletions(-) diff --git a/django/contrib/contenttypes/fields.py b/django/contrib/contenttypes/fields.py index 09d4c1b4a5..fb62f0395b 100644 --- a/django/contrib/contenttypes/fields.py +++ b/django/contrib/contenttypes/fields.py @@ -401,9 +401,6 @@ class GenericRelation(ForeignObject): from_opts = self.remote_field.model._meta return [PathInfo(from_opts, opts, (opts.pk,), self, not self.unique, False)] - def get_choices_default(self): - return super(GenericRelation, self).get_choices(include_blank=False) - def value_to_string(self, obj): qs = getattr(obj, self.name).all() return smart_text([instance._get_pk_val() for instance in qs]) diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 1e04858344..72d5990dc5 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -855,9 +855,6 @@ class Field(RegisterLookupMixin): limit_choices_to)] return first_choice + lst - def get_choices_default(self): - return self.get_choices() - @warn_about_renamed_method( 'Field', '_get_val_from_obj', 'value_from_object', RemovedInDjango20Warning diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index b3e3408c18..082d663c8b 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -14,7 +14,7 @@ from django.db.models.query_utils import PathInfo from django.db.models.utils import make_model_tuple from django.utils import six from django.utils.deprecation import RemovedInDjango20Warning -from django.utils.encoding import force_text, smart_text +from django.utils.encoding import force_text from django.utils.functional import cached_property, curry from django.utils.translation import ugettext_lazy as _ from django.utils.version import get_docs_version @@ -911,18 +911,6 @@ class ForeignKey(ForeignObject): def get_db_prep_value(self, value, connection, prepared=False): return self.target_field.get_db_prep_value(value, connection, prepared) - def value_to_string(self, obj): - if not obj: - # In required many-to-one fields with only one available choice, - # select that one available choice. Note: For SelectFields - # we have to check that the length of choices is *2*, not 1, - # because SelectFields always have an initial "blank" value. - if not self.blank and self.choices: - choice_list = self.get_choices_default() - if len(choice_list) == 2: - return smart_text(choice_list[1][0]) - return super(ForeignKey, self).value_to_string(obj) - def contribute_to_related_class(self, cls, related): super(ForeignKey, self).contribute_to_related_class(cls, related) if self.remote_field.field_name is None: @@ -1455,9 +1443,6 @@ class ManyToManyField(RelatedField): def get_reverse_path_info(self): return self._get_path_info(direct=False) - def get_choices_default(self): - return Field.get_choices(self, include_blank=False) - def _get_m2m_db_table(self, opts): """ Function that can be curried to provide the m2m table name for this @@ -1518,20 +1503,6 @@ class ManyToManyField(RelatedField): break return getattr(self, cache_attr) - def value_to_string(self, obj): - data = '' - if obj: - qs = getattr(obj, self.name).all() - data = [instance._get_pk_val() for instance in qs] - else: - # In required many-to-many fields with only one available choice, - # select that one available choice. - if not self.blank: - choices_list = self.get_choices_default() - if len(choices_list) == 1: - data = [choices_list[0][0]] - return smart_text(data) - def contribute_to_class(self, cls, name, **kwargs): # To support multiple relations to self, it's useful to have a non-None # related name on symmetrical relations for internal reasons. The