Runcible Blog

Now with Tags!

Death to Categories! Long live Tags!

I had been thinking of adding something like those new-fangled "tags" that every website seems to have these days because the current category paradigm seems too static. Well, I just implemented tags after some inspiration from Ross Poulton's post about tags with Django. I took it a step further and tried my hand at "multi-tags" like IMDB's keyword search. I don't think I'll spend too much time refining the tag selection, but it has potential...

For the interested, here's the function that I'm using to render pages when there are multiple tags in the url (the url regex captures any slug + / because I'm not smart enough with regular expressions to split the parts there). It uses a clever (maybe not) method of building Q objects to make a complex query. For one tag urls (like comedy, Django's generic views do the work.

def multitags(request,thetags): query = Q(published__exact=True) splittags = thetags.split('/') for t in splittags: # build a complex query query = query & Q(tags__slug__exact=t) try: entrylist = entries.get_list(complex=query) except entries.EntryDoesNotExist: raise Http404 else: # find the tags tagobjs = [tags.get_object(slug__exact=t) for t in splittags] return render_to_response('blog/tags_multi',{'tags':tagobjs, 'entries':entrylist, 'tagstring': ' '.join(splittags)})