expqr/core/management/commands/addcode.py

14 lines
No EOL
555 B
Python

from django.core.management.base import BaseCommand, CommandError
from core.models import Series, Code
class Command(BaseCommand):
help = 'Add new image series'
def add_arguments(self, parser):
parser.add_argument('title', type=str)
parser.add_argument('--series', required=True, type=str)
def handle(self, *args, **options):
code = Code.objects.create(title=options["title"], series=Series.objects.get(id=options["series"]))
self.stdout.write(self.style.SUCCESS(f'Successfully created code "{ code.id }"'))