0

我想为 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

有什么帮助吗?

谢谢,V。

4

1 回答 1

0

当您在表单中指定字段时,您可以像这样更改小部件:

groups = forms.ModelMultipleChoiceField(queryset=Group.objects.all(), widget=forms.CheckboxSelectMultiple)
于 2013-01-16T14:24:40.170 回答