moviewyrm/bookwyrm/migrations/0005_auto_20200221_1645.py

33 lines
876 B
Python
Raw Normal View History

2020-02-21 17:10:27 +00:00
# Generated by Django 3.0.3 on 2020-02-21 16:45
import re
from django.db import migrations, models
def populate_identifiers(app_registry, schema_editor):
db_alias = schema_editor.connection.alias
2021-03-08 16:49:10 +00:00
tags = app_registry.get_model("bookwyrm", "Tag")
2020-02-21 17:10:27 +00:00
for tag in tags.objects.using(db_alias):
2021-03-08 16:49:10 +00:00
tag.identifier = re.sub(r"\W+", "-", tag.name).lower()
2020-02-21 17:10:27 +00:00
tag.save()
class Migration(migrations.Migration):
dependencies = [
2021-03-08 16:49:10 +00:00
("bookwyrm", "0004_tag"),
2020-02-21 17:10:27 +00:00
]
operations = [
migrations.AddField(
2021-03-08 16:49:10 +00:00
model_name="tag",
name="identifier",
2020-02-21 17:10:27 +00:00
field=models.CharField(max_length=100, null=True),
),
migrations.AlterField(
2021-03-08 16:49:10 +00:00
model_name="tag",
name="name",
2020-02-21 17:10:27 +00:00
field=models.CharField(max_length=100),
),
migrations.RunPython(populate_identifiers),
]