from django.contrib.syndication.feeds import Feed from django.contrib.contenttypes.models import ContentType from django.http import Http404 from jayparlar.tags.models import TaggedItem from jayparlar.blog.models import Post class TagFeed(Feed): def get_object(self, bits): print "BITS", bits if len(bits) != 1: raise TaggedItem.DoesNotExist try: return TaggedItem.objects.filter(tag__exact=bits[0])[0] except: raise TaggedItem.DoesNotExit def title(self, obj): return "JayParlar.com: Items tagged with %s" % obj.tag def link(self, obj): return obj.get_absolute_url() def description(self, obj): return "Items recently tagged with %s" % obj.tag def items(self, obj): # XXX This should probably filter on the Post content type ctype_id = ContentType.objects.get_for_model(Post).id tags = TaggedItem.objects.filter(tag__exact=obj.tag, content_type=ctype_id) items = [] for tag in tags: if tag.content_object.status == "Published": items.append(tag.content_object) return items