You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.1 KiB

  1. from django.db import migrations
  2. def copy_annotation(apps, schema_editor):
  3. Category = apps.get_model('api', 'Category')
  4. Span = apps.get_model('api', 'Span')
  5. for model in [Category, Span]:
  6. for annotation in model.objects.all():
  7. if model == Category:
  8. LabelModel = apps.get_model('api', 'CategoryType')
  9. else:
  10. LabelModel = apps.get_model('api', 'SpanType')
  11. label = LabelModel.objects.get(pk=annotation.label.id)
  12. annotation.new_label = label
  13. annotation.save()
  14. def delete_annotation(apps, schema_editor):
  15. Category = apps.get_model('api', 'Category')
  16. Span = apps.get_model('api', 'Span')
  17. for model in [Category, Span]:
  18. for annotation in model.objects.all():
  19. annotation.new_label = None
  20. annotation.save()
  21. class Migration(migrations.Migration):
  22. dependencies = [
  23. ('api', '0022_auto_20211221_1430'),
  24. ]
  25. operations = [
  26. migrations.RunPython(
  27. code=copy_annotation,
  28. reverse_code=delete_annotation
  29. ),
  30. ]