2011-10-19 96 views
0

我有一些與一些ForeignKey關係的模型。TypeError while rendering:'long'object is iterable

通過forms.py我加了一個ModelMultipleChoiceField部件

class VariableFieldForm(ModelForm): 
    custom_field = forms.ModelMultipleChoiceField(queryset=VariableField.objects.all(), widget=FilteredSelectMultiple("Custom Fields", is_stacked=False)) 

    class Meta: 
     model = VariableField 

,並試圖訪問已保存的記錄localhost:8000/admin/product/subcategory/3/或保存一個新的記錄,我得到以下回溯

File "/opt/python2.6/lib/python2.6/site-packages/django/utils/encoding.py" in force_unicode 
    71. s = unicode(s) 
File "/opt/python2.6/lib/python2.6/site-packages/django/forms/forms.py" in __unicode__ 
    408. return self.as_widget() 
File "/opt/python2.6/lib/python2.6/site-packages/django/forms/forms.py" in as_widget 
    439. return widget.render(name, self.value(), attrs=attrs) 
File "/opt/python2.6/lib/python2.6/site-packages/django/contrib/admin/widgets.py" in render 
    39. output = [super(FilteredSelectMultiple, self).render(name, value, attrs, choices)] 
File "/opt/python2.6/lib/python2.6/site-packages/django/forms/widgets.py" in render 
    581. options = self.render_options(choices, value) 
File "/opt/python2.6/lib/python2.6/site-packages/django/forms/widgets.py" in render_options 
    531. selected_choices = set([force_unicode(v) for v in selected_choices]) 

Exception Type: TemplateSyntaxError at /admin/product/subcategory/3/ 
Exception Value: Caught TypeError while rendering: 'long' object is not iterable 

我使用Django時1.3和MySQL

想法如何解決它?

回答

0

結論是我使用了ForeignKey而不是ManyToManyField關係。

希望這有助於今後的任何問題

相關問題