add 'cat_ids' management command
This commit is contained in:
19
procat2/management/commands/cat_ids.py
Normal file
19
procat2/management/commands/cat_ids.py
Normal file
@ -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)
|
||||
Reference in New Issue
Block a user