1

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.

CDspace
2,69919 gold badges32 silver badges39 bronze badges
asked Mar 24, 2017 at 12:32

1 Answer 1

1

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.

arshovon
13.7k9 gold badges55 silver badges72 bronze badges
answered Mar 24, 2017 at 12:34
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.