diff --git a/apps/transfer/utils.py b/apps/transfer/utils.py index dba43b17..818a8220 100644 --- a/apps/transfer/utils.py +++ b/apps/transfer/utils.py @@ -67,9 +67,9 @@ def get_fields_map(card, queryset): fields_list = list(card['fields'].values())[0] app_queryset_list = [] - print("==============================================================================") - pprint(card) - print("==============================================================================") + # print("==============================================================================") + # pprint(card) + # print("==============================================================================") for legacy_object in queryset.iterator(): app_queryset_dict = {} @@ -77,19 +77,18 @@ def get_fields_map(card, queryset): app_value = convert_field_from_legacy_to_app(legacy_object, legacy_field) if app_value is not None: app_queryset_dict[app_field] = app_value + + if relations is not None: + for relation_table, relation_data in relations.items(): + # print(f"{relation_table.lower()}_set") + print(legacy_object.pagetext) + # relation_object = getattr(legacy_object, f"{relation_table.lower()}_set") + + # print(relation_object) + print("==============================") - pprint(app_queryset_dict) app_queryset_list.append(app_queryset_dict) - # pprint(card) - # print("*************************************") - # pprint(fields_list) - # print("*************************************") - # pprint(relations) - # print("*************************************") - # pprint(len(queryset)) - - return app_queryset_list @@ -178,15 +177,23 @@ def get_legacy_data(card): """Одиночное поле""" legacy_fields.append(legacy_field[0]) - queryset = legacy_model.objects.only(*legacy_fields)[:50]# TODO: remove after debug + queryset = legacy_model.objects.all()[:50]# TODO: remove after debug # Возвращаем зависимости на место - if relations: + if relations is not None: + queryset = add_legacy_relation_data(queryset, relations) card['fields']['relations'] = relations return queryset +# Add relation data to queryset +def add_legacy_relation_data(queryset, relations): + for relation_table in relations.keys(): + queryset = queryset.prefetch_related(relation_table.lower()) + return queryset + + # Models sort def sort_by_dependencies(data): """Сортировка моделей по зависимостям"""