Skip to content
Snippets Groups Projects
Commit 6301d857 authored by Erwan Rouchet's avatar Erwan Rouchet
Browse files

Fix the fixed fix for the fixed migration fix

parent f861c67e
No related branches found
No related tags found
1 merge request!18Transcription search
......@@ -10,8 +10,7 @@ def transcription_to_document(apps, schema_editor):
DocumentLink = apps.get_model('documents', 'DocumentLink')
nb = Transcription.objects.count()
last = 0
links = []
for i, ts in enumerate(Transcription.objects.all()):
for i, ts in enumerate(Transcription.objects.all().prefetch_related('zone__image')):
percent = int(100.0 * (i + 1) / nb)
if percent % 5 == 0 and last != percent:
print(' > {0: >3}% => {1: >6} / {2}'.format(percent, i, nb))
......@@ -20,11 +19,10 @@ def transcription_to_document(apps, schema_editor):
doc.zones.add(ts.zone)
ts.document_ptr_id = doc.id
ts.save()
max_order_dl = DocumentLink.objects.filter(parent_id=ts.zone.document.id).order_by('-order').first()
parent_id = Document.objects.filter(type=DocumentType.Page, zones__image__id=ts.zone.image.id).only('id').get().id
max_order_dl = DocumentLink.objects.filter(parent_id=parent_id).order_by('-order').only('order').first()
order = 0 if max_order_dl is None else max_order_dl.order + 1
links.append(DocumentLink(parent_id=ts.zone.document.id, child_id=doc.id, order=order))
print('Saving document links...')
DocumentLink.objects.bulk_create(links)
DocumentLink.objects.create(parent_id=parent_id, child_id=doc.id, order=order)
class Migration(migrations.Migration):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment