diff --git a/apps/transfer/utils.py b/apps/transfer/utils.py index 55783e9c..32cb4bae 100644 --- a/apps/transfer/utils.py +++ b/apps/transfer/utils.py @@ -2,7 +2,7 @@ from os.path import exists from importlib.machinery import SourceFileLoader from django.apps import apps from collections import OrderedDict -from django.db.models import OuterRef, Subquery +from django.db.models import OuterRef, Subquery, FilteredRelation, Q import transfer.models as legacy_models @@ -118,7 +118,6 @@ def get_relation_data(relations, queryset, fields): """Получаем названия внешних зависимостей""" for relation_table, relation_data in relations.items(): """Если объекты связаны через ForeignKey, то ничего не надо делать - все аннотации уже подключены""" - if isinstance(relation_data['key'], tuple): """Вытаскиваем relation по id""" try: @@ -132,7 +131,9 @@ def get_relation_data(relations, queryset, fields): queryset = queryset.annotate(**{ f"{relation_table.lower()}": - Subquery(child_table_queryset) + Subquery( + child_table_queryset + ) }) return queryset @@ -150,12 +151,17 @@ def get_transfer_data(model, card, queryset): if "fields" not in card or not isinstance(card['fields'], dict) or len(card['fields']) != 1: raise ValueError("You must set correct fields to transfer") - for app_field, legacy_field_data in card['fields'].items(): - print(app_field) - print(legacy_field_data) + # for app_field, legacy_field_data in card['fields'].items(): + # print(app_field) + # print(legacy_field_data) - print("*************************************************************************") + # print("*************************************************************************") # print(app_model) # print("*************************************************************************") # print(queryset) + # for modellt in queryset: + # print(dir(modellt)) + # if hasattr(modellt, "cityphotos_set"): + # print(modellt.cityphotos_set.all()) + # break return queryset