moviewyrm/bookwyrm/migrations/0044_auto_20210207_1924.py

34 lines
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
def set_user(app_registry, schema_editor):
db_alias = schema_editor.connection.alias
shelfbook = app_registry.get_model('bookwyrm', 'ShelfBook')
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 = [
('bookwyrm', '0043_auto_20210204_2223'),
]
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(
model_name='shelfbook',
name='user',
field=bookwyrm.models.fields.ForeignKey(default=2, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL),
preserve_default=False,
),
]