0007_remove_file_blobs_file_blob.py 986 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Generated by Django 4.0.4 on 2022-04-15 14:38
  2. from django.db import migrations, models
  3. import django.db.models.deletion
  4. def forwards_func(apps, schema_editor):
  5. File = apps.get_model("files", "File")
  6. for file in File.objects.all():
  7. file_blob = file.blobs.first()
  8. if file_blob:
  9. file.blob = file_blob
  10. file.save()
  11. def reverse_func(apps, schema_editor):
  12. pass
  13. class Migration(migrations.Migration):
  14. dependencies = [
  15. ("files", "0006_alter_file_headers"),
  16. ]
  17. operations = [
  18. migrations.AddField(
  19. model_name="file",
  20. name="blob",
  21. field=models.ForeignKey(
  22. null=True,
  23. on_delete=django.db.models.deletion.CASCADE,
  24. to="files.fileblob",
  25. ),
  26. ),
  27. migrations.RunPython(forwards_func, reverse_func),
  28. migrations.RemoveField(
  29. model_name="file",
  30. name="blobs",
  31. ),
  32. ]