mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Refs #28011 -- Removed ForeignObjectRel.is_hidden().
This commit is contained in:
parent
6002df0671
commit
f65f8ab84e
@ -154,7 +154,7 @@ class RelatedField(FieldCacheMixin, Field):
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
def _check_related_query_name_is_valid(self):
|
def _check_related_query_name_is_valid(self):
|
||||||
if self.remote_field.is_hidden():
|
if self.remote_field.hidden:
|
||||||
return []
|
return []
|
||||||
rel_query_name = self.related_query_name()
|
rel_query_name = self.related_query_name()
|
||||||
errors = []
|
errors = []
|
||||||
@ -253,7 +253,7 @@ class RelatedField(FieldCacheMixin, Field):
|
|||||||
# If the field doesn't install a backward relation on the target model
|
# If the field doesn't install a backward relation on the target model
|
||||||
# (so `is_hidden` returns True), then there are no clashes to check
|
# (so `is_hidden` returns True), then there are no clashes to check
|
||||||
# and we can skip these fields.
|
# and we can skip these fields.
|
||||||
rel_is_hidden = self.remote_field.is_hidden()
|
rel_is_hidden = self.remote_field.hidden
|
||||||
rel_name = self.remote_field.accessor_name # i. e. "model_set"
|
rel_name = self.remote_field.accessor_name # i. e. "model_set"
|
||||||
rel_query_name = self.related_query_name() # i. e. "model"
|
rel_query_name = self.related_query_name() # i. e. "model"
|
||||||
# i.e. "app_label.Model.field".
|
# i.e. "app_label.Model.field".
|
||||||
@ -887,10 +887,7 @@ class ForeignObject(RelatedField):
|
|||||||
def contribute_to_related_class(self, cls, related):
|
def contribute_to_related_class(self, cls, related):
|
||||||
# Internal FK's - i.e., those with a related name ending with '+' -
|
# Internal FK's - i.e., those with a related name ending with '+' -
|
||||||
# and swapped models don't get a related descriptor.
|
# and swapped models don't get a related descriptor.
|
||||||
if (
|
if not self.remote_field.hidden and not related.related_model._meta.swapped:
|
||||||
not self.remote_field.is_hidden()
|
|
||||||
and not related.related_model._meta.swapped
|
|
||||||
):
|
|
||||||
setattr(
|
setattr(
|
||||||
cls._meta.concrete_model,
|
cls._meta.concrete_model,
|
||||||
related.accessor_name,
|
related.accessor_name,
|
||||||
@ -1901,7 +1898,7 @@ class ManyToManyField(RelatedField):
|
|||||||
or self.remote_field.model == cls._meta.object_name
|
or self.remote_field.model == cls._meta.object_name
|
||||||
):
|
):
|
||||||
self.remote_field.related_name = "%s_rel_+" % name
|
self.remote_field.related_name = "%s_rel_+" % name
|
||||||
elif self.remote_field.is_hidden():
|
elif self.remote_field.hidden:
|
||||||
# If the backwards relation is disabled, replace the original
|
# If the backwards relation is disabled, replace the original
|
||||||
# related_name with one generated from the m2m field name. Django
|
# related_name with one generated from the m2m field name. Django
|
||||||
# still uses backwards relations internally and we need to avoid
|
# still uses backwards relations internally and we need to avoid
|
||||||
@ -1941,10 +1938,7 @@ class ManyToManyField(RelatedField):
|
|||||||
def contribute_to_related_class(self, cls, related):
|
def contribute_to_related_class(self, cls, related):
|
||||||
# Internal M2Ms (i.e., those with a related name ending with '+')
|
# Internal M2Ms (i.e., those with a related name ending with '+')
|
||||||
# and swapped models don't get a related descriptor.
|
# and swapped models don't get a related descriptor.
|
||||||
if (
|
if not self.remote_field.hidden and not related.related_model._meta.swapped:
|
||||||
not self.remote_field.is_hidden()
|
|
||||||
and not related.related_model._meta.swapped
|
|
||||||
):
|
|
||||||
setattr(
|
setattr(
|
||||||
cls,
|
cls,
|
||||||
related.accessor_name,
|
related.accessor_name,
|
||||||
|
@ -187,7 +187,7 @@ class ForwardManyToOneDescriptor:
|
|||||||
# (related_name ends with a '+'). Refs #21410.
|
# (related_name ends with a '+'). Refs #21410.
|
||||||
# The check for len(...) == 1 is a special case that allows the query
|
# The check for len(...) == 1 is a special case that allows the query
|
||||||
# to be join-less and smaller. Refs #21760.
|
# to be join-less and smaller. Refs #21760.
|
||||||
if remote_field.is_hidden() or len(self.field.foreign_related_fields) == 1:
|
if remote_field.hidden or len(self.field.foreign_related_fields) == 1:
|
||||||
query = {
|
query = {
|
||||||
"%s__in"
|
"%s__in"
|
||||||
% related_field.name: {instance_attr(inst)[0] for inst in instances}
|
% related_field.name: {instance_attr(inst)[0] for inst in instances}
|
||||||
|
@ -66,7 +66,8 @@ class ForeignObjectRel(FieldCacheMixin):
|
|||||||
# AttributeError
|
# AttributeError
|
||||||
@cached_property
|
@cached_property
|
||||||
def hidden(self):
|
def hidden(self):
|
||||||
return self.is_hidden()
|
"""Should the related object be hidden?"""
|
||||||
|
return bool(self.related_name) and self.related_name[-1] == "+"
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -191,10 +192,6 @@ class ForeignObjectRel(FieldCacheMixin):
|
|||||||
qs = qs.order_by(*ordering)
|
qs = qs.order_by(*ordering)
|
||||||
return (blank_choice if include_blank else []) + [(x.pk, str(x)) for x in qs]
|
return (blank_choice if include_blank else []) + [(x.pk, str(x)) for x in qs]
|
||||||
|
|
||||||
def is_hidden(self):
|
|
||||||
"""Should the related object be hidden?"""
|
|
||||||
return bool(self.related_name) and self.related_name[-1] == "+"
|
|
||||||
|
|
||||||
def get_joining_columns(self):
|
def get_joining_columns(self):
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"ForeignObjectRel.get_joining_columns() is deprecated. Use "
|
"ForeignObjectRel.get_joining_columns() is deprecated. Use "
|
||||||
|
@ -269,7 +269,7 @@ class RelationTreeTests(SimpleTestCase):
|
|||||||
sorted(
|
sorted(
|
||||||
field.related_query_name()
|
field.related_query_name()
|
||||||
for field in Relation._meta._relation_tree
|
for field in Relation._meta._relation_tree
|
||||||
if not field.remote_field.field.remote_field.is_hidden()
|
if not field.remote_field.field.remote_field.hidden
|
||||||
),
|
),
|
||||||
sorted(
|
sorted(
|
||||||
[
|
[
|
||||||
|
Loading…
Reference in New Issue
Block a user