models.py
中主要i源代码如下:class FileModelForm {
user = models.CharField(verbose_name="用户名", max_length=32)
file_type_choices = (
(1, '文件'),
(2, '文件夹')
)
file_type = models.SmallIntegerField(verbose_name='类型', choices=file_type_choices)
}
form = FileModelForm(data=request.POST)
form.instance.user = 'ruochen'
form.instance.file_type = 1
instance = form.save()
instance.user
获取用户名,通过 instance.get_file_type_display()
获取choice 的中文,即 “文件”。但是实际上 save() 之后通过 instance.get_file_type_display()
获取到的一直是 “1”, 获取不到其中文名称。form = FileModelForm(data=request.POST)
data_dict = form.cleaned_data
data_dict.update({'user': 'ruochen', 'file_type': 1})
instance = models.FileRepository.objects.create(**data_dict)
instance.get_file_type_display()
来获取中文名了本文地址:https://blog.csdn.net/qq_29339467/article/details/107578187
如对本文有疑问, 点击进行留言回复!!
PAT 甲级真题 1006 Sign In and Sign Out (25分) python实现
OpenCV计算机视觉实战(Python)| 03、阈值与平滑处理
网友评论