要解压的值太多 - Django 1.7.11

时间:2016-08-02 10:47:54

标签: python django

我有一个表单,我希望用户选择一个级别。但是,我的模型提出的问题是解包的价值太多了。

我试图将列表中所需的选项放入我之前发现的选项中,但出于某种原因,这次它不会工作。

模型I尝试访问:

class Status(models.Model):
    status_level=models.CharField(max_length=15)

    def __str__(self):
        return self.status_level
    def __iter__(self):
        return iter(self.status_level)

表单本身:

FLAG_CHECKBOX = [('有源''主动&#39),('不活动的''无效'),] STATUS_CHECKBOX = [(Status.objects.all()),]

class Add_Event_Form(forms.ModelForm):

    event_title=forms.CharField(max_length=50,help_text="Please enter an informative title.")
    event_status=forms.MultipleChoiceField(choices=STATUS_CHECKBOX,widget=forms.CheckboxSelectMultiple,help_text="Please select the status of the event")
    event_description=forms.CharField(max_length=500, initial="", help_text="Enter a short description of the event here")
    event_flag=forms.MultipleChoiceField(choices=FLAG_CHECKBOX,required=True,widget=forms.CheckboxSelectMultiple,help_text="Please select the status of this event.")
    date_active=forms.DateField(required=True, widget=forms.DateInput(attrs={'class':'datepicker'}), help_text="Please select a date for this event.")
    time_active=forms.TimeField(required=True, widget=forms.TimeInput(format='%HH:%MM'), help_text="Please select a time for this event.")

标记错误发生位置的行:

H:\interview\server_status\views.py in add_event
    return render(request,'server_status/add_event.html',{'form':form}) 

        return self.get_renderer(name, value, attrs, choices).render() ...
▼ Local vars
Variable    Value
self    
<django.forms.widgets.CheckboxSelectMultiple object at 0x0403A0D0>
choices 
()
name    
'event_status'
value   
None
attrs   
{u'id': u'id_event_status'}
C:\Python27\lib\site-packages\django\forms\widgets.py in render
            choice_value, choice_label = choice ...
▼ Local vars
Variable    Value
id_ 
u'id_event_status'
i   
0
self    
<django.forms.widgets.CheckboxFieldRenderer object at 0x0406DE90>
start_tag   
u'<ul id="id_event_status">'
choice  
[<Status: Critical>, <Status: Medium>, <Status: Low>]
output  
[u'<ul id="id_event_status">']

如果您需要其他信息,请与我们联系。

0 个答案:

没有答案