在我的 django 应用程序中,我正在编写一个自定义管理命令,它将根据传递的参数创建一个对象的实例,并可以选择根据是否有选项将其保存到数据库--save
通过与否。
我在这方面得到了很多帮助Django 文档 https://docs.djangoproject.com/en/2.2/howto/custom-management-commands/本身。还得到了重要的指示here https://stackoverflow.com/questions/10568864/two-arguments-in-django-admin-custom-command关于如何传递多个参数以及here https://stackoverflow.com/questions/4208006/how-does-one-use-django-custom-management-command-option关于如何拥有选择。
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_option 中字段的详细解释。例如optparse.make_option http://nullege.com/codes/search/optparse.make_option lists
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
In this help
是不言自明的,我明白了什么dest
意思是,但我不清楚是什么action='store_true'
方法。事实上,如果有人能给我一个关于所有论点的简短描述,那就太好了make_option
mean...
多谢