forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0004_set_document_m2m_keys.py
More file actions
56 lines (40 loc) · 1.83 KB
/
0004_set_document_m2m_keys.py
File metadata and controls
56 lines (40 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Copyright The IETF Trust 2019-2020, All Rights Reserved
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-05-21 14:27
import sys
from tqdm import tqdm
from django.db import migrations
def forward(apps, schema_editor):
Document = apps.get_model('doc','Document')
CommunityList = apps.get_model('community', 'CommunityList')
CommunityListDocs = apps.get_model('community', 'CommunityListDocs')
SearchRule = apps.get_model('community', 'SearchRule')
SearchRuleDocs = apps.get_model('community', 'SearchRuleDocs')
# Document id fixup ------------------------------------------------------------
objs = Document.objects.in_bulk()
nameid = { o.name: o.id for id, o in objs.items() }
sys.stderr.write('\n')
sys.stderr.write(' %s.%s:\n' % (CommunityList.__name__, 'added_docs'))
count = 0
for l in tqdm(CommunityList.objects.all()):
for d in l.added_docs.all():
count += 1
CommunityListDocs.objects.get_or_create(communitylist=l, document_id=nameid[d.name])
sys.stderr.write(' %s CommunityListDocs objects created\n' % (count, ))
sys.stderr.write(' %s.%s:\n' % (SearchRule.__name__, 'name_contains_index'))
count = 0
for r in tqdm(SearchRule.objects.all()):
for d in r.name_contains_index.all():
count += 1
SearchRuleDocs.objects.get_or_create(searchrule=r, document_id=nameid[d.name])
sys.stderr.write(' %s SearchRuleDocs objects created\n' % (count, ))
def reverse(apps, schema_editor):
pass
class Migration(migrations.Migration):
dependencies = [
('community', '0003_add_communitylist_docs2_m2m'),
('doc', '0014_set_document_docalias_id'),
]
operations = [
migrations.RunPython(forward, reverse),
]