I'm using django-taggit (see here). This is what I have:
forms.py
from taggit.forms import *
class MyForm(forms.Form):
title = forms.CharField()
my_tags = TagField(max_length=800, widget=forms.TextInput(attrs={'class':'myTags'}))
views.py
if 'submit_button' in request.POST:
form = MyForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
f_title = cd['title']
f_my_tags = cd['my_tags']
p = MyData.objects.create(title=f_title)
p.tags.add(f_my_tags)
p.save()
mytemplate.html
{{ form.my_tags.errors }}
{{ form.my_tags }}
Not sure why I get unhashable type: 'list'
when I use p.tags.add(f_my_tags)
in my views.py. Any ideas? Thank you!
You need to either add tags individually:
this is equivalent to:
or pass them as positional arguments to tags.add:
this being equivalent to: p.tags.add(cd['my_tags'][0], cd['my_tags][1]... )