I have got trouble with django tagging - filtering by tags consisting of several words does not work. models
class MyWidget(models.Model):
"""Widget for tagging. It's damn bugged, so it need try except statement
for be able to import in shell and work in general. Otherwise it's raiseing
exception."""
name = models.CharField(max_length = 50)
try:
tagging.register(MyWidget)
except tagging.AlreadyRegistered:
pass
views
class PostsByTags(ListView):
"""View returns news filtered by tag."""
template_name = 'news.djhtml'
contect_object_name = 'news_list'
def get_queryset(self):
tags = unquote(self.kwargs['tag'])
return TaggedItem.objects.get_by_model(News(), tags)
urls
url(r'^news/(?P<tag>[\w\s]*)/$', views.PostsByTags.as_view(),
name = 'tagged_news'),
If url looking something like that
/news/separated%20tag/
the view class returns empty list. What the cause? How can I fix it?
I thinks the query tag is being split into two (in tagging.utils.parse_tag_input).
get_by_model can also take a Tag item rather then a string, so try something like.
tag_object = Tag.objects.get(name=self.kwargs['tag'])
TaggedItem.objects.get_by_model(News(), tag_object)