moviewyrm/bookwyrm/migrations/0086_auto_20210828_1724.py

50 lines
1.4 KiB
Python
Raw Normal View History

2021-08-28 17:33:57 +00:00
# Generated by Django 3.2.4 on 2021-08-28 17:24
import bookwyrm.models.fields
from django.conf import settings
from django.db import migrations, models
from django.db.models import F, Value, CharField
from django.db.models.functions import Concat
def forwards_func(apps, schema_editor):
"""generate followers url"""
db_alias = schema_editor.connection.alias
apps.get_model("bookwyrm", "User").objects.using(db_alias).annotate(
generated_url=Concat(
F("remote_id"), Value("/followers"), output_field=CharField()
)
).update(followers_url=models.F("generated_url"))
def reverse_func(apps, schema_editor):
"""noop"""
2021-08-28 17:33:57 +00:00
class Migration(migrations.Migration):
dependencies = [
("bookwyrm", "0085_user_saved_lists"),
2021-08-28 17:33:57 +00:00
]
operations = [
migrations.AddField(
model_name="user",
name="followers_url",
field=bookwyrm.models.fields.CharField(
default="/followers", max_length=255
),
2021-08-28 17:33:57 +00:00
preserve_default=False,
),
migrations.RunPython(forwards_func, reverse_func),
2021-08-28 17:33:57 +00:00
migrations.AlterField(
model_name="user",
name="followers",
field=models.ManyToManyField(
related_name="following",
through="bookwyrm.UserFollows",
to=settings.AUTH_USER_MODEL,
),
2021-08-28 17:33:57 +00:00
),
]