我想用必需和可选参数实现导入功能,以这种方式运行:
python manage.py import --mode archive
Run Code Online (Sandbox Code Playgroud)
哪里--mode是必要的,archive也是.
我正在使用argparse库.
class Command(BaseCommand):
help = 'Import'
def add_arguments(self, parser):
parser.add_argument('--mode',
required=True,
)
parser.add_argument('archive',
required=True,
default=False,
help='Make import archive events'
)
Run Code Online (Sandbox Code Playgroud)
但我收到了错误:
TypeError: 'required' is an invalid argument for positionals
Run Code Online (Sandbox Code Playgroud) 我不是 JavaScript 专家,但我有一个带有 js 和插件 VIDEOJS 的项目(Video.js v4.6.4 版权所有 2014 Brightcove, Inc. https://github.com/videojs/video.js/blob/master/)。
我收到一个错误:
video.dev.js:1384 VIDEOJS: 错误: (代码:4 MEDIA_ERR_SRC_NOT_SUPPORTED) 无法加载视频,可能是因为服务器或网络出现故障,也可能是因为格式不受支持。
我知道可以解决这个问题:<source src="video/test.m3u8" type="application/x-mpegURL">.但我的问题是,如何做到这一点。
我在 Django 1.8 中有管理面板,我的代码在 admin.py 文件中:
这是我的模型的一部分:
TYPES_CHOICES = (
('normal', 'normal'),
('archive', 'archive'),
)
class Period(models.Model):
date_start = models.DateTimeField(help_text='date_start')
date_end = models.DateTimeField(help_text='date_end')
type = models.CharField(choices=TYPES_CHOICES, default=TYPES_CHOICES[0][0], max_length=10)
class PeriodAdmin(admin.ModelAdmin):
list_display = ('id', 'date_start', 'date_end', 'description',
'note', 'is_published', 'is_actual', 'type', )
search_fields = ('id', 'note', 'description', 'description_en',)
fields = ['type', ]
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何将类型字段切换为可编辑字段,切换字段值表单模型。我找不到这是文档。请提供任何提示。