我有一个匹配模型:
class Match(models.Model):
base_f = models.CharField(max_length=255)
base_v = models.IntegerField()
dest_f = models.CharField(max_length=255)
dest_v = models.IntegerField()
我从Match
模型创建了一个模型表单:
class MatchForm(forms.ModelForm):
class Meta:
model = Match
widgets = {
'base_f':forms.Select(choices=base_fs, attrs={'class':'base_f'}),
'base_v':forms.Select(attrs={'class':'dest_v'}),
'dest_f':forms.Select(choices=dest_fs, attrs={'class':'dest_f'}),
'dest_v':forms.Select(attrs={'class':'dest_v'}),
}
form.save() 适用于这个模型表单。但我想使用SelectMultiple
. 但是 form.save() 不会在数据库中添加任何数据,格式如下:
class MatchForm(forms.ModelForm):
class Meta:
model = Match
widgets = {
'base_f':forms.Select(choices=base_fs, attrs={'class':'base_f'}),
'base_v':forms.SelectMultiple(attrs={'class':'dest_v'}),
'dest_f':forms.Select(choices=dest_fs, attrs={'class':'dest_f'}),
'dest_v':forms.SelectMultiple(attrs={'class':'dest_v'}),
}
我可以在 django 中将 SelectMultiple 模型与 CharFiled 一起使用吗?
提前致谢