Object Is Not Iterable - Django Modelform
I'm using Model forms to add a row to a table in Django, here are my views and forms file views.py def add_ad_mod(request): current_user = request.user current_ip = get_c
Solution 1:
As I mentioned in the comments, it looks like both of these fields should be multiple choice, since they are both representing ManyToManyFields in the model.
self.fields['sub_category'] = forms.ModelMultipleChoiceField(label="Sniffer", queryset=SubCate.objects.filter(main_category=current_categ))
self.fields['sub_location'] = forms.ModelMultipleChoiceField (widget=forms.CheckboxSelectMultiple,label="Sniffer", queryset=SubLoc.objects.filter(main_town=current_loc))
Also as mentioned, you need to call save on the model instance, and save_m2m on the form:
if add_ad_mod_form.is_valid():
model_instance = add_ad_mod_form.save(commit=False)
...
model_instance.save()
add_ad_mod_form.save_m2m()
return redirect('dashboard')
Post a Comment for "Object Is Not Iterable - Django Modelform"