Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Django feeds as a class based views.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 doc
Octocat-spinner-32 syndication
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE
Octocat-spinner-32 MANIFEST.in
Octocat-spinner-32 README.markdown
Octocat-spinner-32 setup.py
README.markdown

syndication-view

syndication-view is a refactor of Django's syndication contrib app, primarily to turn feeds into class-based views, but will also fix a number of long standing tickets.

Installation

$ python setup.py install

Usage

articles/feeds.py:

from syndication.views import Feed
from articles.models import Article, Category

class ArticleFeed(Feed):
    title = "example.com news"
    link = "/sitenews/"
    description = "Latest news from example.com."

    def items(self):
        return Article.objects.all()[:15]

class CategoryArticleFeed(ArticleFeed):
    def title(self, obj):
        return 'example.com: %s' % obj

    def get_object(self, request, slug):
        return Category.objects.get(slug=slug)

    def items(self, obj):
        return Article.objects.filter(category=obj)[:15]

urls.py:

from articles.feeds import ArticleFeed, CategoryArticleFeed

urlpatterns = patterns('',
    # ...
    (r'^articles/feed/$', ArticleFeed()),
    (r'^articles/feed/(?P<slug>[a-z0-9\-]+)/$', CategoryArticleFeed()),
    # ...
)

The API for the feed object in syndication.views is almost identical to that in Django's contrib app, except get_object() takes the request and any arguments passed to it from the URL rather than the "bits".

Something went wrong with that request. Please try again.