表单中使用的窗口小部件未出现在网页上。 Django 1.11.5

时间:2018-02-23 07:40:38

标签: python django django-models django-forms

所以我有forms.py

扩展/ forms.py

from django import forms
from .models import SipExtension
from xmpp.models import xmpp_buddy_groups

class ExtensionForm(forms.ModelForm):
    xmpp_buddy_groups_choices = xmpp_buddy_groups.objects.values_list('group_name',flat=True)
   # xmpp_buddy_groups_names = forms.ModelMultipleChoiceField(queryset=xmpp_buddy_groups_choices,widget=forms.CheckboxSelectMultiple,required=False)
    class Meta:
      model = SipExtension
      fields = '__all__'
      widgets = {
            'xmpp_buddy_groups_names': forms.CheckboxSelectMultiple
        }

我的扩展应用和xmpp应用的模型如下: 扩展/ model.py

class SipExtension(models.Model):
    sip_extension = models.PositiveIntegerField(unique=True)
    sip_secret = models.CharField(max_length=32)
    commlink_push = models.BooleanField(default=False)
    real_name = models.CharField(max_length=32,unique=True)
    xmpp = models.BooleanField(default= False)
    xmpp_username = models.CharField(max_length=50,default='username')
    xmpp_password = models.CharField(max_length=32,default='password')
    xmpp_buddy_groups_names = models.ManyToManyField('xmpp.xmpp_buddy_groups',blank=True)


    def __str__(self):
        return '%s : %s' % (self.sip_extension, self.real_name)

XMPP / models.py

class xmpp_buddy_groups(models.Model):
    group_name = models.CharField(max_length=30)

    def __str__(self):
        return '%s' % (self.group_name)

我想在我的gui中使用extensions / forms.py

中的复选框

但我得到的是:

enter image description here

1 个答案:

答案 0 :(得分:0)

我相信你必须传递一个小部件的实例,而不是一个对小部件类的引用。像这样:

widgets = {
    'xmpp_buddy_groups_names': forms.CheckboxSelectMultiple()
}