2022-02-24 20:48:52 +00:00
|
|
|
# Generated by Django 3.2.12 on 2022-02-24 20:41
|
|
|
|
|
|
|
|
from django.db import migrations, models
|
|
|
|
import django.db.models.deletion
|
|
|
|
|
|
|
|
|
|
|
|
def set_report_statuses(apps, schema_editor):
|
|
|
|
"""copy over status fields"""
|
|
|
|
db_alias = schema_editor.connection.alias
|
|
|
|
report_model = apps.get_model("bookwyrm", "Report")
|
|
|
|
reports = report_model.objects.using(db_alias).filter(statuses__isnull=False)
|
|
|
|
for report in reports:
|
|
|
|
report.status = report.statuses.first()
|
|
|
|
report.save()
|
|
|
|
|
2022-02-24 21:20:18 +00:00
|
|
|
|
2022-02-24 20:48:52 +00:00
|
|
|
def set_reverse(apps, schema_editor):
|
|
|
|
"""copy over status fields"""
|
|
|
|
db_alias = schema_editor.connection.alias
|
|
|
|
report_model = apps.get_model("bookwyrm", "Report")
|
|
|
|
reports = report_model.objects.using(db_alias).filter(status__isnull=False)
|
|
|
|
for report in reports:
|
|
|
|
report.statuses.set(report.status)
|
|
|
|
|
2022-02-24 21:20:18 +00:00
|
|
|
|
2022-02-24 20:48:52 +00:00
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
dependencies = [
|
2022-02-24 21:20:18 +00:00
|
|
|
("bookwyrm", "0138_automod"),
|
2022-02-24 20:48:52 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.AddField(
|
2022-02-24 21:20:18 +00:00
|
|
|
model_name="report",
|
|
|
|
name="status",
|
|
|
|
field=models.ForeignKey(
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
on_delete=django.db.models.deletion.PROTECT,
|
|
|
|
related_name="reports",
|
|
|
|
to="bookwyrm.status",
|
|
|
|
),
|
2022-02-24 20:48:52 +00:00
|
|
|
),
|
|
|
|
migrations.RunPython(set_report_statuses, reverse_code=set_reverse),
|
|
|
|
]
|