From a86ebe8a53fc46dafa389fe779807fa5c5d9bb81 Mon Sep 17 00:00:00 2001 From: Seth Ladygo Date: Fri, 25 Oct 2019 16:30:02 -0700 Subject: [PATCH] add 'cat_ids' management command --- procat2/management/commands/cat_ids.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 procat2/management/commands/cat_ids.py diff --git a/procat2/management/commands/cat_ids.py b/procat2/management/commands/cat_ids.py new file mode 100644 index 0000000..29053df --- /dev/null +++ b/procat2/management/commands/cat_ids.py @@ -0,0 +1,19 @@ +from django.core.management.base import BaseCommand, CommandError +from procat2.models import Catalog + + +class Command(BaseCommand): + help = 'Return material numbers for a catalog' + + def add_arguments(self, parser): + parser.add_argument('cat_ids', nargs='+', type=int) + + def handle(self, *args, **options): + for cat_id in options['cat_ids']: + try: + cat = Catalog.objects.get(pk=cat_id) + except Catalog.DoesNotExist: + raise CommandError('Catalog "%s" does not exist' % cat_id) + + for id in cat.product_ids(): + self.stdout.write(id)