Django admin:使用多个选择复选框的选项渲染模型字段

时间:2014-10-14 13:20:48

标签: python django model

我想将模型字段渲染为复选框,以便我将选项预定义为元组列表,我该怎么做?

class Car(models.Model):
    groups = models.CharField(max_length=100,
                              blank=False)

class CarAdmin(forms.ModelForm):

    def __init__(self, *args, **kwargs):
        super(CarForm, self).__init__(*args, **kwargs)
        self.fields['groups'].widget = forms.CheckboxSelectMultiple(choices=CARS_ALLOWED)

0 个答案:

没有答案