【发布时间】:2009-09-09 13:14:55
【问题描述】:
假设我有如下定义的选择:
choices = (('1','a'),
('2','b'),
('3','c'))
以及在 MultipleChoiceField 中呈现和输入这些值的表单,
class Form1(forms.Form):
field = forms.MultipleChoiceField(choices=choices)
在模型中存储field 的正确方法是什么。
我当然可以遍历forms.cleaned_data['field'] 并获得一个适合models.CommaSeperatedIntegerField 的值。
同样,每次检索这些值时,我都必须循环并转换为选项。
我认为有更好的方法可以做到这一点,因为这样,我在某种程度上重新实现了 CommaSeperateIntegerField 应该做的功能。
【问题讨论】:
标签: python django django-models django-forms