在我的Django应用程序中,我正在编写一个自定义管理命令,该命令将根据传递的参数创建对象的实例,并且可以根据是否传递选项--save
来 Select 将其保存到数据库.
在这件事上,我从django documentation本身得到了很多帮助.我还从here得到了关于如何传递多个参数的重要提示,从here得到了关于如何拥有选项的重要提示.
from optparse import make_option
class Command(BaseCommand):
option_list = BaseCommand.option_list + (
make_option('--delete',
action='store_true',
dest='delete',
default=False,
help='Delete poll instead of closing it'),
)
def handle(self, *args, **options):
# ...
if options['delete']:
poll.delete()
# ...
但是,我无法找到make_选项中字段的详细说明.例如,optparse.make_option个列表
Instance attributes:
_short_opts : [string]
_long_opts : [string]
action : string
type : string
dest : string
default : any
nargs : int
const : any
choices : [string]
callback : function
callback_args : (any*)
callback_kwargs : { string : any }
help : string
metavar : string
在这help
是不言而喻的,我知道dest
是什么意思,但我不清楚action='store_true'
是什么意思.事实上,如果有人能给我一个简短的描述,make_option
的所有论点是什么意思,那就太好了.
谢谢