alex/django-taggit — Issue #90: TagWidget.render assumes value is queryset
Author: tedtieken
Created: 2011-12-19 21:26:59+00:00
State: open

For a complicated set of reasons, I intercept and modify the tags on my object before rendering the form. Some of them get displayed in their own true-false fields, others get displayed as tags.

To do this, in my form's __init__ method I do some work on the tags, then reset the initial values of the tag field to a list of tags.

However, the TagWidget.render method assumes it is getting a queryset, not a list. As lists have no attribute select_related, this fails.

To fix I have changed the TagWidget.render method as such:

class TagWidget(forms.TextInput):
def render(self, name, value, attrs=None):
from django.db.models.query import QuerySet
if type(value) == QuerySet:
value = value.select_related("tag")
if value is not None and not isinstance(value, basestring):
value = edit_string_for_tags([o.tag for o in value])
return super(TagWidget, self).render(name, value, attrs)