Refactored to polyphonic package
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
import argparse
|
||||
import csv
|
||||
|
||||
from library import models
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
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")
|
||||
|
||||
def handle(self, *args, **options):
|
||||
|
||||
collection = models.Collection.objects.get(pk=options["collection"])
|
||||
|
||||
reader = csv.DictReader(options["source"])
|
||||
for row in reader:
|
||||
collection.works.create(
|
||||
name=row["Piece"], composer=row["Composer"], notes=row["Notes"]
|
||||
)
|
||||
Reference in New Issue
Block a user