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.

35 lines
1.1 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  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(code=copy_annotation, reverse_code=delete_annotation),
  27. ]