for folder in Folder objects filter is_object_root True project__conte

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
for folder in Folder.objects.filter(is_object_root=True, project__content_type__pk__in=[matter_ct.pk, submatter_ct.pk, event_ct.pk]):
project = Project.objects.get(pk=folder.project.id)
print(project.content_type.model)
if project.content_type == matter_ct:
print('if matter')
matter_id = project.object_id
first_submatter = SubMatter.objects.filter(matter_id=matter_id).first()
if first_submatter:
Folder.objects.filter(tree_id=folder.tree_id).update(sub_matter=first_submatter)
if project.content_type == submatter_ct:
print('if sub_matter')
sub_matter = SubMatter.objects.get(pk=project.object_id)
Folder.objects.filter(tree_id=folder.tree_id).update(sub_matter=sub_matter)
if project.content_type == event_ct:
print('if event')
event = Event.objects.get(pk=project.object_id)
Folder.objects.filter(tree_id=folder.tree_id).update(sub_matter=event.sub_matter, event=event)
else:
print("else")
print(project.content_type.model)
print('_______________________')