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.

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.