TypeError while rendering: 'long' object is not iterable

1.1k Views Asked by At

I have a few models with some ForeignKey relationship.

Through forms.py I added a ModelMultipleChoiceField widget

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

    class Meta:
        model = VariableField

and when trying to access a saved record localhost:8000/admin/product/subcategory/3/ or saving a new record I get the following traceback

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

I am using Django 1.3 and MySQL

Ideas on how to solve it?

1

There are 1 best solutions below

0
On

Ended up being that I used a ForeignKey, instead of a ManyToManyField relation.

Hope this helps any future questions