Django Aggregator v2 now has tagging, and you should too.

I have been doing some more work on my Django Community Aggregator / Django People v2 project. A big feature that I want to incorporate is tagging. I want people to be able to sort data by tag, among other things. I think that this is a pretty killer feature.

This allows someone to say “I want to get all of the data about testing or debugging that the Django community is doing”. However, if nobody is tagging their posts, then only services that provide tags will be available in those views. A lot of people are using django-tagging on the backend of their blogs, but they just aren’t exposing that data in feeds.

Note: Yes I know the data can’t be edited yet (on the aggregator). That is because it is a project that is just living on my site for the moment. Once it gets moved off and the Uber community of Django gets more off the ground, all of those issues will be solved.

Luckily, it is really easy to expose your tagging data in your Django feeds. This assumes you are using Django Tagging, however, it’s really easy with anything else.

Say we have our feed class that looks like this.

class BlogPostsFeed(Feed):
    title = 'My awesome blog'
    description = 'My awesome blog"

    def link(self):
        return ""

    def items(self):
        return Post.objects.published()[:10]

    def item_pubdate(self, obj):
        return obj.publish

That is a pretty basic feed, but much akin to what most people have. Now lets add some tagging in there! Assuming that you have the Tag model imported from tagging, you can simply do this:

def item_categories(self, obj):
    return [ for tag in  Tag.objects.get_for_object(obj)]

You can test to make sure that your feeds are working by using feedparser

In [1]: import feedparser

In [3]: p = feedparser.parse('')

In [4]: p.entries[0].tags
[{'label': None, 'scheme': None, 'term': u'lawrence'},
 {'label': None, 'scheme': None, 'term': u'mediaphormedia'},
 {'label': None, 'scheme': None, 'term': u'philosophy'},
 {'label': None, 'scheme': None, 'term': u'post-a-day'},
 {'label': None, 'scheme': None, 'term': u'ramblings'}]

That’s it! Now everyone go do that to their feeds, so that I can harvest your tags and make them useful :)

Hey there! I'm Eric and I work on communities in the world of software documentation. Feel free to email me if you have comments on this post!