0
カスタムコマンドを複数の都市のIDで実行したいとします。私はそれをどのようにするのですか?私はドキュメンテーションで何も見つからなかった。このコマンドはpython manage.py command_name 1
のためにかなりうまく機能カスタムdjango-admin manage.pyコマンドを実行するには
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
:これは私のコマンドのソースコードです。 id = 1の都市をプリントします。しかし、同じコマンドを何度も実行することなく、ID1,2を持つ都市を印刷したいと思います。 python manage.py command_name 1, 2
またはpython manage.py command_name [1,2,3]
です。このようなものは動作しません。