0014_person_enable_default_workflow.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Generated by Django 4.2 on 2023-05-15 11:13
  2. from django.db import migrations
  3. def add_default_workflow(apps, schema_editor):
  4. Workflow = apps.get_model("wagtailcore", "Workflow")
  5. WorkflowContentType = apps.get_model("wagtailcore", "WorkflowContentType")
  6. ContentType = apps.get_model("contenttypes", "ContentType")
  7. Person = apps.get_model("base", "Person")
  8. default_workflow = Workflow.objects.filter(active=True).first()
  9. person_ct = ContentType.objects.get_for_model(Person)
  10. WorkflowContentType.objects.create(
  11. workflow=default_workflow,
  12. content_type=person_ct,
  13. )
  14. def remove_default_workflow(apps, schema_editor):
  15. WorkflowContentType = apps.get_model("wagtailcore", "WorkflowContentType")
  16. ContentType = apps.get_model("contenttypes", "ContentType")
  17. Person = apps.get_model("base", "Person")
  18. person_ct = ContentType.objects.get_for_model(Person)
  19. WorkflowContentType.objects.filter(content_type=person_ct).delete()
  20. class Migration(migrations.Migration):
  21. dependencies = [
  22. ("base", "0013_person_lockablemixin"),
  23. ("wagtailcore", "0083_workflowcontenttype"),
  24. ]
  25. operations = [
  26. migrations.RunPython(
  27. add_default_workflow,
  28. remove_default_workflow,
  29. ),
  30. ]