2020-11-04 18:35:13 +00:00
|
|
|
# Generated by Django 3.0.7 on 2020-11-04 18:15
|
|
|
|
|
|
|
|
from django.db import migrations, models
|
|
|
|
import django.db.models.deletion
|
|
|
|
|
|
|
|
|
|
|
|
def set_default_edition(app_registry, schema_editor):
|
|
|
|
db_alias = schema_editor.connection.alias
|
2021-03-08 16:49:10 +00:00
|
|
|
works = app_registry.get_model("bookwyrm", "Work").objects.using(db_alias)
|
|
|
|
editions = app_registry.get_model("bookwyrm", "Edition").objects.using(db_alias)
|
2020-11-04 18:35:13 +00:00
|
|
|
for work in works:
|
|
|
|
ed = editions.filter(parent_work=work, default=True).first()
|
|
|
|
if not ed:
|
|
|
|
ed = editions.filter(parent_work=work).first()
|
|
|
|
work.default_edition = ed
|
|
|
|
work.save()
|
|
|
|
|
2021-03-08 16:49:10 +00:00
|
|
|
|
2020-11-04 18:35:13 +00:00
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
dependencies = [
|
2021-03-08 16:49:10 +00:00
|
|
|
("bookwyrm", "0007_auto_20201103_0014"),
|
2020-11-04 18:35:13 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.AddField(
|
2021-03-08 16:49:10 +00:00
|
|
|
model_name="work",
|
|
|
|
name="default_edition",
|
|
|
|
field=models.ForeignKey(
|
|
|
|
null=True,
|
|
|
|
on_delete=django.db.models.deletion.PROTECT,
|
|
|
|
to="bookwyrm.Edition",
|
|
|
|
),
|
2020-11-04 18:35:13 +00:00
|
|
|
),
|
|
|
|
migrations.RunPython(set_default_edition),
|
|
|
|
migrations.RemoveField(
|
2021-03-08 16:49:10 +00:00
|
|
|
model_name="edition",
|
|
|
|
name="default",
|
2020-11-04 18:35:13 +00:00
|
|
|
),
|
|
|
|
]
|