Reputation: 2929
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?
Upvotes: 0
Views: 202
Reputation: 5382
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/
Upvotes: 1