Updates report model
This commit is contained in:
37
bookwyrm/migrations/0139_report_status.py
Normal file
37
bookwyrm/migrations/0139_report_status.py
Normal file
@ -0,0 +1,37 @@
|
||||
# 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()
|
||||
|
||||
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)
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('bookwyrm', '0138_automod'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
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'),
|
||||
),
|
||||
migrations.RunPython(set_report_statuses, reverse_code=set_reverse),
|
||||
]
|
Reference in New Issue
Block a user