Reputation: 53
I would like to run my custom command with more than one city's id. How to I do that? I didn't find anythind in the documentation. This is source code of my command:
from django.core.management.base import BaseCommand, CommandError
from reservation.models import City
class Command(BaseCommand):
help = 'Closes the specified poll for voting'
def add_arguments(self, parser):
parser.add_argument('city_id', nargs='+', type=int)
def handle(self, *args, **options):
for city_id in options['city_id']:
try:
city = City.objects.get(pk=city_id)
except City.DoesNotExist:
raise CommandError('City "%s" does not exist' % city_id)
print city
This command works pretty well for python manage.py command_name 1
. It prints city with id=1. But I would like to print city with id 1,2.. without executing the same command multiple times. It is python manage.py command_name 1, 2
or python manage.py command_name [1,2,3]
. Something like this doesn't work.
Upvotes: 1
Views: 1558
Reputation: 53
Well, I just realized that I should execute:
python manage.py command_name 1 2 3
to print city with id 1, 2 and 3.
Upvotes: 1