我试图在一个基于类的视图中有两个表单。 我的观点是:
class ListAndCreate(CreateView):
model = xmpp_buddy_groups
form_class = xmpp_buddy_groups_form
second_form_class = sip_extension_form
template_name = "xmpp/index.html"
success_url = reverse_lazy('xmpp:index')
def get_context_data(self, **kwargs):
context = super(ListAndCreate, self).get_context_data(**kwargs)
context['object_list'] = self.model.objects.all()
extension = SipExtension.objects.values_list('sip_extension', flat=True)
for buddy_groups in group_names:
for sip in buddy_groups.sipextension_set.all():
sip_extension = sip.sip_extension
print(sip_extension)
context['extension'] = extension
SipExtension.objects.exclude(sip_extension__in=extension)
print(extension)
context['form'] = self.form_class(request = self.request)
context['form2'] = self.second_form_class(request=self.request)
context['extensions'] = SipExtension.objects.exclude(sip_extension__in=extension)
return context
我收到错误 init ()得到了一个意外的关键字参数' request'。我哪里错了?
我的表单类:
from django import forms
from .models import xmpp_buddy_groups
from extensions.models import SipExtension
class xmpp_buddy_groups_form(forms.ModelForm):
class Meta:
model = xmpp_buddy_groups
fields = ['group_name']
def __init__(self, *args, **kwargs):
super(xmpp_buddy_groups_form, self).__init__(*args, **kwargs)
self.fields['group_name'].required = False
class sip_extension_form(forms.ModelForm):
class Meta:
model = SipExtension
fields = ['real_name','sip_extension']
widgets = {
"sip_extension": forms.Select
}