2013-01-16 65 views
0

我想爲M2M使用垂直複選框。這裏是一個代碼示例:django表單 - 爲M2M呈現垂直複選框

class Contact(models.Model): 
    ... 
    groups = models.ManyToManyField (
     Group, 
     related_name = "contacts", 
     verbose_name = _("Groups"), 
    ) 
    ... 

class Group (models.Model): 
    name = models.CharField (
     unique = True, 
     max_length = 100, 
     db_index = True, 
    ) 

class ContactAdminForm(forms.ModelForm): 
    class Meta: 
     model = Contact 

    radio_fields = {"groups": admin.VERTICAL} # only for foreignkey or for choices 

對此有何幫助?

感謝, 五

回答

0

當你在表單中指定的領域,你可以改變,像這樣的小部件:

groups = forms.ModelMultipleChoiceField(queryset=Group.objects.all(), widget=forms.CheckboxSelectMultiple)