mirror of https://github.com/django/django.git
Cached ForeignObject.(local/foreign/reverse)_related_fields properties.
This commit is contained in:
parent
e7d62e97eb
commit
c1b24718e0
|
@ -616,21 +616,19 @@ class ForeignObject(RelatedField):
|
||||||
related_fields.append((from_field, to_field))
|
related_fields.append((from_field, to_field))
|
||||||
return related_fields
|
return related_fields
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def related_fields(self):
|
def related_fields(self):
|
||||||
if not hasattr(self, '_related_fields'):
|
return self.resolve_related_fields()
|
||||||
self._related_fields = self.resolve_related_fields()
|
|
||||||
return self._related_fields
|
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def reverse_related_fields(self):
|
def reverse_related_fields(self):
|
||||||
return [(rhs_field, lhs_field) for lhs_field, rhs_field in self.related_fields]
|
return [(rhs_field, lhs_field) for lhs_field, rhs_field in self.related_fields]
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def local_related_fields(self):
|
def local_related_fields(self):
|
||||||
return tuple(lhs_field for lhs_field, rhs_field in self.related_fields)
|
return tuple(lhs_field for lhs_field, rhs_field in self.related_fields)
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def foreign_related_fields(self):
|
def foreign_related_fields(self):
|
||||||
return tuple(rhs_field for lhs_field, rhs_field in self.related_fields if rhs_field)
|
return tuple(rhs_field for lhs_field, rhs_field in self.related_fields if rhs_field)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue