This commit is contained in:
littlewolf 2019-10-14 16:30:26 +03:00
parent 54cfccbcbe
commit 8cae39cbb6

View File

@ -2,7 +2,7 @@ from os.path import exists
from importlib.machinery import SourceFileLoader from importlib.machinery import SourceFileLoader
from django.apps import apps from django.apps import apps
from collections import OrderedDict 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 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(): for relation_table, relation_data in relations.items():
"""Если объекты связаны через ForeignKey, то ничего не надо делать - все аннотации уже подключены""" """Если объекты связаны через ForeignKey, то ничего не надо делать - все аннотации уже подключены"""
if isinstance(relation_data['key'], tuple): if isinstance(relation_data['key'], tuple):
"""Вытаскиваем relation по id""" """Вытаскиваем relation по id"""
try: try:
@ -132,7 +131,9 @@ def get_relation_data(relations, queryset, fields):
queryset = queryset.annotate(**{ queryset = queryset.annotate(**{
f"{relation_table.lower()}": f"{relation_table.lower()}":
Subquery(child_table_queryset) Subquery(
child_table_queryset
)
}) })
return 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: 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") raise ValueError("You must set correct fields to transfer")
for app_field, legacy_field_data in card['fields'].items(): # for app_field, legacy_field_data in card['fields'].items():
print(app_field) # print(app_field)
print(legacy_field_data) # print(legacy_field_data)
print("*************************************************************************") # print("*************************************************************************")
# print(app_model) # print(app_model)
# print("*************************************************************************") # print("*************************************************************************")
# print(queryset) # print(queryset)
# for modellt in queryset:
# print(dir(modellt))
# if hasattr(modellt, "cityphotos_set"):
# print(modellt.cityphotos_set.all())
# break
return queryset return queryset