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

Fixed the fix for the fixed migration fix

parent 8c3e00c8
No related branches found
No related tags found
1 merge request!18Transcription search
......@@ -7,17 +7,21 @@ from documents.models import DocumentType
def transcription_to_document(apps, schema_editor):
Document = apps.get_model('documents', 'Document')
Transcription = apps.get_model('documents', 'Transcription')
nb = Transcription.objects.all().count()
DocumentLink = apps.get_model('documents', 'DocumentLink')
nb = Transcription.objects.count()
last = 0
for i, ts in enumerate(Transcription.objects.all()):
percent = int(100.0 * (i + 1) / nb)
if percent % 5 == 0 and last != percent:
print(' > {}% => {} / {}'.format(percent, i, nb))
print(' > {0: >3}% => {1: >6} / {2}'.format(percent, i, nb))
last = percent
doc = Document.objects.create(id=ts.id, type=DocumentType.Transcription, name="Transcription '{}'".format(ts.text))
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()
order = 0 if max_order_dl is None else max_order_dl.order + 1
DocumentLink.objects.create(parent_id=ts.zone.document.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