Browse Source

Enable workflows on Person model

Sage Abdullah 1 năm trước cách đây
mục cha
commit
050daa7d5a

+ 43 - 0
bakerydemo/base/migrations/0014_person_enable_default_workflow.py

@@ -0,0 +1,43 @@
+# Generated by Django 4.2 on 2023-05-15 11:13
+
+from django.db import migrations
+
+
+def add_default_workflow(apps, schema_editor):
+    Workflow = apps.get_model("wagtailcore", "Workflow")
+    WorkflowContentType = apps.get_model("wagtailcore", "WorkflowContentType")
+    ContentType = apps.get_model("contenttypes", "ContentType")
+    Person = apps.get_model("base", "Person")
+
+    default_workflow = Workflow.objects.filter(active=True).first()
+    person_ct = ContentType.objects.get_for_model(Person)
+
+    WorkflowContentType.objects.create(
+        workflow=default_workflow,
+        content_type=person_ct,
+    )
+
+
+def remove_default_workflow(apps, schema_editor):
+    WorkflowContentType = apps.get_model("wagtailcore", "WorkflowContentType")
+    ContentType = apps.get_model("contenttypes", "ContentType")
+    Person = apps.get_model("base", "Person")
+
+    person_ct = ContentType.objects.get_for_model(Person)
+
+    WorkflowContentType.objects.filter(content_type=person_ct).delete()
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("base", "0013_person_lockablemixin"),
+        ("wagtailcore", "0083_workflowcontenttype"),
+    ]
+
+    operations = [
+        migrations.RunPython(
+            add_default_workflow,
+            remove_default_workflow,
+        ),
+    ]

+ 2 - 0
bakerydemo/base/models.py

@@ -20,6 +20,7 @@ from wagtail.models import (
     Page,
     PreviewableMixin,
     RevisionMixin,
+    WorkflowMixin,
 )
 from wagtail.search import index
 
@@ -27,6 +28,7 @@ from .blocks import BaseStreamBlock
 
 
 class Person(
+    WorkflowMixin,
     DraftStateMixin,
     LockableMixin,
     RevisionMixin,