mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-15 20:56:34 +00:00
Updates migration
This commit is contained in:
parent
15555e61d0
commit
e99e4831f1
2 changed files with 100 additions and 35 deletions
|
@ -1,35 +0,0 @@
|
||||||
# Generated by Django 3.2 on 2021-05-21 00:17
|
|
||||||
|
|
||||||
from django.db import migrations
|
|
||||||
import bookwyrm
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("bookwyrm", "0075_announcement"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RenameField(
|
|
||||||
model_name="edition",
|
|
||||||
old_name="physical_format",
|
|
||||||
new_name="physical_format_detail",
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="edition",
|
|
||||||
name="physical_format",
|
|
||||||
field=bookwyrm.models.fields.CharField(
|
|
||||||
blank=True,
|
|
||||||
choices=[
|
|
||||||
("AudiobookFormat", "Audiobookformat"),
|
|
||||||
("EBook", "Ebook"),
|
|
||||||
("GraphicNovel", "Graphicnovel"),
|
|
||||||
("Hardcover", "Hardcover"),
|
|
||||||
("Paperback", "Paperback"),
|
|
||||||
],
|
|
||||||
max_length=255,
|
|
||||||
null=True,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
# Generated by Django 3.2 on 2021-05-21 00:17
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
import bookwyrm
|
||||||
|
|
||||||
|
|
||||||
|
def infer_format(app_registry, schema_editor):
|
||||||
|
"""set the new phsyical format field based on existing format data"""
|
||||||
|
db_alias = schema_editor.connection.alias
|
||||||
|
|
||||||
|
editions = (
|
||||||
|
app_registry.get_model("bookwyrm", "Edition")
|
||||||
|
.objects.using(db_alias)
|
||||||
|
.filter(physical_format__isnull=False)
|
||||||
|
)
|
||||||
|
mappings = {
|
||||||
|
"paperback": "Paperback",
|
||||||
|
"soft": "Paperback",
|
||||||
|
"pamphlet": "Paperback",
|
||||||
|
"peperback": "Paperback",
|
||||||
|
"tapa blanda": "Paperback",
|
||||||
|
"turtleback": "Paperback",
|
||||||
|
"pocket": "Paperback",
|
||||||
|
"spiral": "Paperback",
|
||||||
|
"ring": "Paperback",
|
||||||
|
"平装": "Paperback",
|
||||||
|
"简装": "Paperback",
|
||||||
|
"hardcover": "Hardcover",
|
||||||
|
"hardcocer": "Hardcover",
|
||||||
|
"hardover": "Hardcover",
|
||||||
|
"hardback": "Hardcover",
|
||||||
|
"library": "Hardcover",
|
||||||
|
"tapa dura": "Hardcover",
|
||||||
|
"leather": "Hardcover",
|
||||||
|
"clothbound": "Hardcover",
|
||||||
|
"精装": "Hardcover",
|
||||||
|
"ebook": "EBook",
|
||||||
|
"e-book": "EBook",
|
||||||
|
"digital": "EBook",
|
||||||
|
"computer file": "EBook",
|
||||||
|
"epub": "EBook",
|
||||||
|
"online": "EBook",
|
||||||
|
"pdf": "EBook",
|
||||||
|
"elektronische": "EBook",
|
||||||
|
"electronic": "EBook",
|
||||||
|
"audiobook": "AudiobookFormat",
|
||||||
|
"audio": "AudiobookFormat",
|
||||||
|
"cd": "AudiobookFormat",
|
||||||
|
"dvd": "AudiobookFormat",
|
||||||
|
"mp3": "AudiobookFormat",
|
||||||
|
"cassette": "AudiobookFormat",
|
||||||
|
"kindle": "AudiobookFormat",
|
||||||
|
"talking": "AudiobookFormat",
|
||||||
|
"sound": "AudiobookFormat",
|
||||||
|
"comic": "GraphicNovel",
|
||||||
|
"graphic": "GraphicNovel",
|
||||||
|
}
|
||||||
|
for edition in editions:
|
||||||
|
free_format = editions.physical_format_detail.lower()
|
||||||
|
if free_format in mappings:
|
||||||
|
edition.physical_format = mappings[free_format]
|
||||||
|
edition.save(broadcast=False)
|
||||||
|
else:
|
||||||
|
matches = [v for k, v in mappings if k in free_format]
|
||||||
|
if not matches:
|
||||||
|
continue
|
||||||
|
edition.physical_format = matches[0]
|
||||||
|
edition.save(broadcast=False)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("bookwyrm", "0076_preview_images"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name="edition",
|
||||||
|
old_name="physical_format",
|
||||||
|
new_name="physical_format_detail",
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="edition",
|
||||||
|
name="physical_format",
|
||||||
|
field=bookwyrm.models.fields.CharField(
|
||||||
|
blank=True,
|
||||||
|
choices=[
|
||||||
|
("AudiobookFormat", "Audiobookformat"),
|
||||||
|
("EBook", "Ebook"),
|
||||||
|
("GraphicNovel", "Graphicnovel"),
|
||||||
|
("Hardcover", "Hardcover"),
|
||||||
|
("Paperback", "Paperback"),
|
||||||
|
],
|
||||||
|
max_length=255,
|
||||||
|
null=True,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.RunPython(infer_format),
|
||||||
|
]
|
Loading…
Reference in a new issue