views:

23

answers:

1

What would be a way to have date range based rss feeds in Django. For instance if I had the following type of django rss feed model.

from django.contrib.syndication.feeds import Feed
from myapp.models import *

class PopularFeed(Feed):
    title = '%s : Latest SOLs' % settings.SITE_NAME
    link = '/'
    description = 'Latest entries to %s' % settings.SITE_NAME

    def items(self):
        return sol.objects.order_by('-date')

What would be a way to have PopularFeed used for All Time, Last Month, Last Week, Last 24 Hours, and vice-versa if I wanted to have LeastPopularFeed?

+1  A: 

You need to define a class for each feed you want. For example for Last Month feed:

class LastMonthFeed(Feed):

    def items(self):
        ts = datetime.datetime.now() - datetime.timedelta(days=30)
        return sol.object.filter(date__gte=ts).order_by('-date')

Then add these feeds to your urls.py as shown in docs: http://docs.djangoproject.com/en/1.2/ref/contrib/syndication/

Andrey Fedoseev