Fixes migration query

This commit is contained in:
Mouse Reeve 2021-06-19 08:37:53 -07:00
parent cb811c92a6
commit f82161d648

View file

@ -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"""