moviewyrm/bookwyrm/migrations/0044_auto_20210207_1924.py

39 lines
1.1 KiB
Python
Raw Normal View History

2021-02-07 19:29:13 +00:00
# Generated by Django 3.0.7 on 2021-02-07 19:24
import bookwyrm.models.fields
from django.conf import settings
from django.db import migrations
import django.db.models.deletion
2021-03-08 16:49:10 +00:00
2021-02-07 19:29:13 +00:00
def set_user(app_registry, schema_editor):
db_alias = schema_editor.connection.alias
2021-03-08 16:49:10 +00:00
shelfbook = app_registry.get_model("bookwyrm", "ShelfBook")
2021-02-07 19:29:13 +00:00
for item in shelfbook.objects.using(db_alias).filter(user__isnull=True):
item.user = item.shelf.user
2021-02-11 01:30:26 +00:00
try:
item.save(broadcast=False)
except TypeError:
item.save()
2021-02-07 19:29:13 +00:00
class Migration(migrations.Migration):
dependencies = [
2021-03-08 16:49:10 +00:00
("bookwyrm", "0043_auto_20210204_2223"),
2021-02-07 19:29:13 +00:00
]
operations = [
2021-02-09 19:21:43 +00:00
migrations.RunPython(set_user, lambda x, y: None),
2021-02-07 19:29:13 +00:00
migrations.AlterField(
2021-03-08 16:49:10 +00:00
model_name="shelfbook",
name="user",
field=bookwyrm.models.fields.ForeignKey(
default=2,
on_delete=django.db.models.deletion.PROTECT,
to=settings.AUTH_USER_MODEL,
),
2021-02-07 19:29:13 +00:00
preserve_default=False,
),
]