3.3 KiB
relations.relation_proxy
RelationProxy Objects
class RelationProxy(list)
Proxy of the Relation that is a list with special methods.
related_field_name
| @property
| related_field_name() -> str
On first access calculates the name of the related field, later stored in _related_field_name property.
Returns:
(str): name of the related field
__getattribute__
| __getattribute__(item: str) -> Any
Since some QuerySetProxy methods overwrite builtin list methods we catch calls to them and delegate it to QuerySetProxy instead.
Arguments:
item (str): name of attribute
Returns:
(Any): value of attribute
__getattr__
| __getattr__(item: str) -> Any
Delegates calls for non existing attributes to QuerySetProxy.
Arguments:
item (str): name of attribute/method
Returns:
(method): method from QuerySetProxy if exists
_initialize_queryset
| _initialize_queryset() -> None
Initializes the QuerySetProxy if not yet initialized.
_check_if_queryset_is_initialized
| _check_if_queryset_is_initialized() -> bool
Checks if the QuerySetProxy is already set and ready.
Returns:
(bool): result of the check
_check_if_model_saved
| _check_if_model_saved() -> None
Verifies if the parent model of the relation has been already saved. Otherwise QuerySetProxy cannot filter by parent primary key.
_set_queryset
| _set_queryset() -> "QuerySet"
Creates new QuerySet with relation model and pre filters it with currents parent model primary key, so all queries by definition are already related to the parent model only, without need for user to filter them.
Returns:
(QuerySet): initialized QuerySet
remove
| async remove(item: "Model", keep_reversed: bool = True) -> None
Removes the item from relation with parent.
Through models are automatically deleted for m2m relations.
For reverse FK relations keep_reversed flag marks if the reversed models should be kept or deleted from the database too (False means that models will be deleted, and not only removed from relation).
Arguments:
item (Model): child to remove from relationkeep_reversed (bool): flag if the reversed model should be kept or deleted too
add
| async add(item: "Model") -> None
Adds child model to relation.
For ManyToMany relations through instance is automatically created.
Arguments:
item (Model): child to add to relation