在我的django应用程序中,我正在编写一个自定义管理命令,它将根据传递的args创建一个对象实例,并可以根据是否--save传递一个选项将其保存到数据库中.
我从django文档中获得了很多帮助.也得到了重要指针这里了解如何传递多个参数,并在这里了解如何有选择.
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()
# ...
Run Code Online (Sandbox Code Playgroud)
但是我无法找到make_option中字段的详细说明.例如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 : …Run Code Online (Sandbox Code Playgroud)