LoginSignup
1
1

More than 5 years have passed since last update.

--no-input をcall_command のoption指定 にしたい場合

Posted at

Djangoでcall_commandのoption指定で迷ったのでメモ

# Similar to the command line
management.call_command('dumpdata', '--natural-foreign')

# Named argument similar to the command line minus the initial dashes and
# with internal dashes replaced by underscores
management.call_command('dumpdata', natural_foreign=True)

# `use_natural_foreign_keys` is the option destination variable
management.call_command('dumpdata', use_natural_foreign_keys=True)

参照 django

と記述してあるので、

python manage.py flush --noinput
を実行したい場合は、

management.call_command('flush',noinput=True)

で動くと思ったが一向にnoinputが効かなかった。

そこでいろいろ調べると
https://github.com/django/django/blob/master/django/core/management/commands/flush.py#L20
ということらしい。
そこで

management.call_command('flush',interactive=False)

としたら動いた。

ドキュメントに書いてないような……。ソース読めってことなのか……。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1