WIP skip relation registration on m2m through instance, simplify registering relations part 2

This commit is contained in:
collerek
2021-01-10 12:06:49 +01:00
parent 055c99ba02
commit 4071ff7d11
13 changed files with 114 additions and 120 deletions

View File

@ -63,7 +63,7 @@ class Relation:
self._type: RelationType = type_
self._to_remove: Set = set()
self.to: Type["T"] = to
self.through: Optional[Type["T"]] = through
self._through: Optional[Type["T"]] = through
self.field_name = field_name
self.related_models: Optional[Union[RelationProxy, "T"]] = (
RelationProxy(relation=self, type_=type_, field_name=field_name)
@ -71,6 +71,12 @@ class Relation:
else None
)
@property
def through(self) -> Type["T"]:
if not self._through: # pragma: no cover
raise RelationshipInstanceError("Relation does not have through model!")
return self._through
def _clean_related(self) -> None:
"""
Removes dead weakrefs from RelationProxy.