wip - through models fields -> attached in queries, accesible from instances, creates in add and queryset create

This commit is contained in:
collerek
2021-02-15 17:30:14 +01:00
parent 868243686d
commit 3fd231cf3c
19 changed files with 677 additions and 374 deletions

View File

@ -291,6 +291,8 @@ class SqlJoin:
self.get_order_bys(
to_table=to_table, pkname_alias=pkname_alias,
)
else:
self.select_through_model_fields()
self_related_fields = self.next_model.own_table_columns(
model=self.next_model,
@ -305,6 +307,24 @@ class SqlJoin:
)
self.used_aliases.append(self.next_alias)
def select_through_model_fields(self) -> None:
# TODO: add docstring
next_alias = self.alias_manager.resolve_relation_alias(
from_model=self.target_field.owner, relation_name=self.relation_name
)
# TODO: fix fields and exclusions
self_related_fields = self.target_field.through.own_table_columns(
model=self.target_field.through,
fields=None,
exclude_fields=self.target_field.through.extract_related_names(),
use_alias=True,
)
self.columns.extend(
self.alias_manager.prefixed_columns(
next_alias, self.target_field.through.Meta.table, self_related_fields
)
)
def _replace_many_to_many_order_by_columns(self, part: str, new_part: str) -> None:
"""
Substitutes the name of the relation with actual model name in m2m order bys.