mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-15 04:36:34 +00:00
Fixes migration query
This commit is contained in:
parent
cb811c92a6
commit
f82161d648
1 changed files with 5 additions and 8 deletions
|
@ -11,7 +11,7 @@ def infer_format(app_registry, schema_editor):
|
||||||
editions = (
|
editions = (
|
||||||
app_registry.get_model("bookwyrm", "Edition")
|
app_registry.get_model("bookwyrm", "Edition")
|
||||||
.objects.using(db_alias)
|
.objects.using(db_alias)
|
||||||
.filter(physical_format__isnull=False)
|
.filter(physical_format_detail__isnull=False)
|
||||||
)
|
)
|
||||||
mappings = {
|
mappings = {
|
||||||
"paperback": "Paperback",
|
"paperback": "Paperback",
|
||||||
|
@ -56,19 +56,16 @@ def infer_format(app_registry, schema_editor):
|
||||||
"graphic": "GraphicNovel",
|
"graphic": "GraphicNovel",
|
||||||
}
|
}
|
||||||
for edition in editions:
|
for edition in editions:
|
||||||
free_format = editions.physical_format_detail.lower()
|
free_format = edition.physical_format_detail.lower()
|
||||||
print(free_format)
|
|
||||||
if free_format in mappings:
|
if free_format in mappings:
|
||||||
print("hi")
|
|
||||||
edition.physical_format = mappings[free_format]
|
edition.physical_format = mappings[free_format]
|
||||||
edition.save(broadcast=False)
|
edition.save()
|
||||||
else:
|
else:
|
||||||
matches = [v for k, v in mappings if k in free_format]
|
matches = [v for k, v in mappings.items() if k in free_format]
|
||||||
print(matches)
|
|
||||||
if not matches:
|
if not matches:
|
||||||
continue
|
continue
|
||||||
edition.physical_format = matches[0]
|
edition.physical_format = matches[0]
|
||||||
edition.save(broadcast=False)
|
edition.save()
|
||||||
|
|
||||||
def reverse(app_registry, schema_editor):
|
def reverse(app_registry, schema_editor):
|
||||||
"""doesn't need to do anything"""
|
"""doesn't need to do anything"""
|
||||||
|
|
Loading…
Reference in a new issue