Question

I currently have an entry in urls.py which fetches lone permalinks for my bugs:

from django.conf.urls.defaults import *

from tagging.views import tagged_object_list

from bugs.models import Bug

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Example:
    # (r'^workarounds/', include('workarounds.foo.urls')),

    # Uncomment the admin/doc line below and add 'django.contrib.admindocs' 
    # to INSTALLED_APPS to enable admin documentation:
    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    (r'^$', 'django.views.generic.simple.direct_to_template', {'template':'homepage.html'}),

    (r'^bugs/(?P<slug>[-\w]+)/$', 'bugs.views.bug_detail'),
    (r'^bugs/tagged/(?P<tag>[^/]+)/$', 
    'tagging.views.tagged_object_list',
    {
        'queryset_or_model': Bug,
        'template_name' : 'tag/lone.html'}),
    # Uncomment the next line to enable the admin:
    (r'^admin/', include(admin.site.urls)),
)

So if I specified a url of say, bugs/tagged/firefox it would bring up firefox tags. How could I make it filter out by multiple tags? eg: firefox+css would return all objects tagged with firefox and css.

Was it helpful?

Solution

You'll have to build your own view instead of using tagging.views.tagged_object_list.

(r'^bugs/tagged/(?P<tags>[-\w+]+)/$', your_tag_view)

In your view, get a list of the tags you are searching for:

tags = tags.split('+')

Then, use the TaggedItem.objects.get_by_model query, which conveniently will accept a list of tags:

from tagging.models import TaggedItem
bugs = TaggedItem.objects.get_by_model(Bug, tags)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top