Library cleanup

This commit is contained in:
2026-05-12 11:03:11 +10:00
parent 75dced77b8
commit 4164d56dea
11 changed files with 588 additions and 326 deletions
@@ -4,17 +4,20 @@ import csv
from library import models
class Command(BaseCommand):
help = 'Imports works from a csv file'
help = "Imports works from a csv file"
def add_arguments(self, parser):
parser.add_argument('collection', type=int, help="Collection ID")
parser.add_argument('source', type=argparse.FileType('r'), help="Source CSV")
parser.add_argument("collection", type=int, help="Collection ID")
parser.add_argument("source", type=argparse.FileType("r"), help="Source CSV")
def handle(self, *args, **options):
collection = models.Collection.objects.get(pk=options['collection'])
collection = models.Collection.objects.get(pk=options["collection"])
reader = csv.DictReader(options['source'])
reader = csv.DictReader(options["source"])
for row in reader:
collection.works.create(name=row['Piece'], composer=row['Composer'], notes=row['Notes'])
collection.works.create(
name=row["Piece"], composer=row["Composer"], notes=row["Notes"]
)