0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-29 09:33:54 +01:00

Add migration to populate WorkflowState's content_type and base_content_type fields

This commit is contained in:
Sage Abdullah 2022-12-13 15:50:26 +00:00
parent 3cf2c0dc19
commit 90a3813418
No known key found for this signature in database
GPG Key ID: EB1A33CC51CC0217

View File

@ -0,0 +1,41 @@
# Generated by Django 4.2.dev20221212151407 on 2022-12-12 15:16
from django.db import migrations, models
from django.db.models.functions import Cast
def populate_workflowstate_content_type(apps, schema_editor):
ContentType = apps.get_model("contenttypes.ContentType")
WorkflowState = apps.get_model("wagtailcore.WorkflowState")
Page = apps.get_model("wagtailcore.Page")
page_type = ContentType.objects.get(app_label="wagtailcore", model="page")
content_type_id = models.Subquery(
Page.objects.filter(
pk=Cast(models.OuterRef("object_id"), models.PositiveIntegerField())
).values("content_type_id")
)
WorkflowState.objects.all().update(
base_content_type=page_type,
content_type_id=content_type_id,
)
def empty_workflowstate_content_type(apps, schema_editor):
WorkflowState = apps.get_model("wagtailcore.WorkflowState")
WorkflowState.objects.all().update(base_content_type=None, content_type=None)
class Migration(migrations.Migration):
dependencies = [
("wagtailcore", "0080_generic_workflowstate"),
]
operations = [
migrations.RunPython(
populate_workflowstate_content_type,
empty_workflowstate_content_type,
)
]