Thanks to y'alls valuable comments and a morning cup of coffee, I took a deep dive into my code. I got it working after fixing the errors. Here is the error that I had in my models.py:
class Exp(models.Model):
# The first element in each tuple is the actual value to be stored. The second element is the human-readable name for the option.
CATEGORIES = ( ('Inc', 'Inc'),\
('Clv','Clv'), \
('Dys', 'Dys'), \
('Hom', 'Hom'), \
('Syn','Syn') )
#category = models.CharField(max_length=100, choices=CATEGORIES) <--- culprit
I did not realize that my original definition of category was still lingering around. I commented that out in models.py and it worked as expected!
Here is my forms.py:
class ExpForm(ModelForm):
category = forms.MultipleChoiceField(choices=Exp.CATEGORIES,widget=forms.CheckboxSelectMultiple())
class Meta:
model = Exp
Here is my views.py:
def view_experiment(request):
if request.method == "POST":
form = ExpForm(request.POST)
if form.is_valid():
picked = form.cleaned_data.get('category')
category = ",".join([str(c) for c in picked])
return HttpResponse("Multichoiceselect returned {0}".format(category))
else:
return "[ERROR] from views: {0}".format(form.errors)
else:
form = ExpForm()
return render(request, 'template.html', {'form': form})
The selected multiple choices is returned as a list of unicode strings. I then converted the list elements to a string and joined them with a comma.