I've created a Feed subclass to export a simple feed of news
#urls.py
from django.conf.urls.defaults import *
from litenewz.feeds import NewsFeed
feeds = {
'news': NewsFeed,
}
urlpatterns = patterns(
'',
(r'^feeds/(?P<url>.*)/$',
'django.contrib.syndication.views.feed',
{'feed_dict': feeds}),
)
#feeds.py
from django.contrib.syndication.feeds import Feed
from litenewz.models import News
class NewsFeed(Feed):
title = 'example news'
link = 'http://example.net'
description = 'Latest Newz from example.'
item_author_name = '...'
item_author_email = '...'
item_author_link = 'http://example.net'
def items(self):
return News.objects.order_by('-time')[:15]
#models.py
from django.db import models
from django.utils.translation import ugettext as _
from datetime import datetime
class News(models.Model):
class Meta:
ordering = ('-time', )
verbose_name = _('News')
verbose_name_plural = _('News')
title = models.CharField(
_('Title'),
max_length=512)
time = models.DateTimeField(
_('Date and time'),
default=datetime.now
)
content = models.TextField(
_('Content'))
def __unicode__(self):
return self.title
@models.permalink
def get_absolute_url(self):
return ('home', (), {})
As you can see the Feed
subclass' items()
method returns the first 15 objects in News.objects.order_by('-time')
:
def items(self):
return News.objects.order_by('-time')[:15]
Nevertheless, only one item is exported in the feed: hxxp://www.sshguard.net/litenewz/feeds/news/
Unfortunately, there are two objects of the News model:
>>> from litenewz.models import *
>>> News.objects.all()
[<News: Version 1.5 and timing>, <News: SSHGuard news>]
Any help?
I prefer not to switch to Django 1.2, unless this is strictly necessary to solve the issue described.
Update: the RSS returned indeed contains both the objects, but the RSS is not valid and thus readers such as Safari's are fooled: