I'm trying to use taggit in a form, but I'm getting this message:
'unicode' object has no attribute 'set'
for the method save_m2m. This is my code.
if form.is_valid():
response = form.save(commit=False)
#response = super(ReviewForm, self).save(commit=False)
response.user = user
response.tag = form.cleaned_data['tag']
response.product = product
response.review_text = form.cleaned_data['review_text']
response.created = time.strftime("%c")
response.updated = time.strftime("%c")
response.save()
form.save_m2m()
Full traceback: Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/kinect-xbox-360/review_submit/
Django Version: 1.6.1
Python Version: 2.7.5
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'reviews',
'south',
'taggit')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/filipeferminiano/Documents/django/consumidor/consumidor/reviews/views.py" in single_product
89. form.save_m2m()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/forms/models.py" in save_m2m
96. f.save_form_data(instance, cleaned_data[f.name])
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/taggit/managers.py" in save_form_data
125. getattr(instance, self.name).set(*value)
Exception Type: AttributeError at /kinect-xbox-360/review_submit/
Exception Value: 'unicode' object has no attribute 'set'
I'm following taggit docs:
I am not very familiar with django-taggit but in ReviewForm try changing
tag = forms.CharField( ...
to something like
tags = TagField()
or use
'tags': TagWidget()
see django - django-taggit form and Django-Taggit in Edit Form