1
0
Fork 0

Adds managment command to repair editions in bad state

This commit is contained in:
Mouse Reeve 2023-07-17 11:20:36 -07:00
parent fbb9d75cc8
commit eee4e30e25
3 changed files with 54 additions and 0 deletions

View file

@ -0,0 +1,21 @@
""" Repair editions with missing works """
from django.core.management.base import BaseCommand
from bookwyrm import models
class Commmand(BaseCommand):
"""command-line options"""
help = "Repairs an edition that is in a broken state"
# pylint: disable=unused-argument
def handle(self, *args, **options):
"""Find and repair broken editions"""
# Find broken editions
editions = models.Edition.objects.filter(parent_work__isnull=True)
self.stdout.write(f"Repairing {editions.count()} edition(s):")
# Do repair
for edition in editions:
edition.repair()
self.stdout.write(".", ending="")