タイトルは実際にそれをすべて言うが、私は現在、これを持っているが、それは動作しません:django管理コマンドでサブパパラを作成することはできますか?
class Command(BaseCommand):
help = ("Functions related to downloading, parsing, and indexing the "
"content")
def add_arguments(self, parser):
subparsers = parser.add_subparsers()
download_parser = subparsers.add_parser(
'download',
help='Using a local CSV, download the XML data for content. '
'Output is sent to the log.'
)
download_parser.add_argument(
'--start_line',
type=int,
default=0,
help='The line in the file where you wish to start processing.'
)
# Add an argparse parser for parsing the content. Yes, this is
# a bit confusing.
content_parser_parser = subparsers.add_parser(
'parse',
help="Look at the file system and parse everything you see so that "
"we have content in the databse."
)
content_parser_parser.add_argument(
'--start_item',
type=int,
default=0,
help="Assuming the content is sorted by file name, this item is "
"the one to start on."
)
私の具体的なアイデアは、XMLコンテンツをダウンロードするか、データベースにそれを解析するためのサブコマンドがあり一つのコマンドを作成することです。
すでに 'parser'にあるもの知らず、あるいはどのような' django'、後でそれでそれをしない、私が言うことができません。あなたのサブパーザの定義はうまくいきます。しかし、他のSOの質問から分かるように、サブパーザを他の引数、位置および/またはオプションで使用することは難しい可能性があります。診断のように、関数の先頭に 'print parser._actions'を追加してください。 – hpaulj
http://stackoverflow.com/questions/31919101/djangos-call-command-fails-with-missing-required-argumentsは、argparseとdjangoの両方に関係する以前の質問の1つです。 djangoはoptparseの使用に似ていますが、最近argparseの代替が追加されました。 – hpaulj