first passing to clean and check

This commit is contained in:
collerek
2020-12-15 11:55:07 +01:00
parent eeee0409ac
commit 1b42d321b9
8 changed files with 136 additions and 27 deletions

View File

@ -89,13 +89,13 @@ def register_reverse_model_fields(
) -> None:
if issubclass(model_field, ManyToManyField):
model.Meta.model_fields[child_model_name] = ManyToMany(
child, through=model_field.through, name=child_model_name, virtual=True
child, through=model_field.through, name=child_model_name, virtual=True, related_name=model_field.name
)
# register foreign keys on through model
adjust_through_many_to_many_model(model, child, model_field)
else:
model.Meta.model_fields[child_model_name] = ForeignKey(
child, real_name=child_model_name, virtual=True
child, real_name=child_model_name, virtual=True, related_name=model_field.name
)

View File

@ -62,10 +62,11 @@ class ModelTableProxy:
@staticmethod
def get_clause_target_and_filter_column_name(
parent_model: Type["Model"], target_model: Type["Model"], reverse: bool
parent_model: Type["Model"], target_model: Type["Model"], reverse: bool, related: str,
) -> Tuple[Type["Model"], str]:
if reverse:
field = target_model.resolve_relation_field(target_model, parent_model)
field = parent_model.Meta.model_fields[related]
# field = target_model.resolve_relation_field(target_model, parent_model)
if issubclass(field, ormar.fields.ManyToManyField):
sub_field = target_model.resolve_relation_field(
field.through, parent_model