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)