summaryrefslogtreecommitdiff
path: root/docs/syndication_feeds.txt
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-05-02 01:31:56 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-05-02 01:31:56 +0000
commitf69cf70ed813a8cd7e1f963a14ae39103e8d5265 (patch)
treed3b32e84cd66573b3833ddf662af020f8ef2f7a8 /docs/syndication_feeds.txt
parentd5dbeaa9be359a4c794885c2e9f1b5a7e5e51fb8 (diff)
MERGED MAGIC-REMOVAL BRANCH TO TRUNK. This change is highly backwards-incompatible. Please read http://code.djangoproject.com/wiki/RemovingTheMagic for upgrade instructions.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@2809 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/syndication_feeds.txt')
-rw-r--r--docs/syndication_feeds.txt26
1 files changed, 13 insertions, 13 deletions
diff --git a/docs/syndication_feeds.txt b/docs/syndication_feeds.txt
index d234c2b7ec..b7b0a9047b 100644
--- a/docs/syndication_feeds.txt
+++ b/docs/syndication_feeds.txt
@@ -93,7 +93,7 @@ This simple example, taken from `chicagocrime.org`_, describes a feed of the
latest five news items::
from django.contrib.syndication.feeds import Feed
- from django.models.chicagocrime import newsitems
+ from chicagocrime.models import NewsItem
class SiteNewsFeed(Feed):
title = "Chicagocrime.org site news"
@@ -101,7 +101,7 @@ latest five news items::
description = "Updates on changes and additions to chicagocrime.org."
def items(self):
- return newsitems.get_list(order_by=('-pub_date',), limit=5)
+ return NewsItem.objects.order_by('-pub_date')[:5]
Note:
@@ -120,10 +120,11 @@ One thing's left to do. In an RSS feed, each ``<item>`` has a ``<title>``,
put into those elements.
* To specify the contents of ``<title>`` and ``<description>``, create
- `Django templates`_ called ``feeds/sitenews_title`` and
- ``feeds/sitenews_description``, where ``sitenews`` is the ``slug``
- specified in the URLconf for the given feed. The RSS system renders that
- template for each item, passing it two template context variables:
+ `Django templates`_ called ``feeds/sitenews_title.html`` and
+ ``feeds/sitenews_description.html``, where ``sitenews`` is the ``slug``
+ specified in the URLconf for the given feed. Note the ``.html`` extension
+ is required. The RSS system renders that template for each item, passing
+ it two template context variables:
* ``{{ obj }}`` -- The current object (one of whichever objects you
returned in ``items()``).
@@ -175,7 +176,7 @@ An example makes this clear. Here's the code for these beat-specific feeds::
# check that bits has only one member.
if len(bits) != 1:
raise ObjectDoesNotExist
- return beats.get_object(beat__exact=bits[0])
+ return Beat.objects.get(beat__exact=bits[0])
def title(self, obj):
return "Chicagocrime.org: Crimes for beat %s" % obj.beat
@@ -187,7 +188,7 @@ An example makes this clear. Here's the code for these beat-specific feeds::
return "Crimes recently reported in police beat %s" % obj.beat
def items(self, obj):
- return crimes.get_list(beat__id__exact=obj.id, order_by=(('-crime_date'),), limit=30)
+ return Crime.objects.filter(beat__id__exact=obj.id).order_by('-crime_date')[:30]
Here's the basic algorithm the RSS framework follows, given this class and a
request to the URL ``/rss/beats/0613/``:
@@ -203,8 +204,8 @@ request to the URL ``/rss/beats/0613/``:
the beat. Note that ``get_object()`` should raise
``django.core.exceptions.ObjectDoesNotExist`` if given invalid
parameters. There's no ``try``/``except`` around the
- ``beats.get_object()`` call, because it's not necessary; that function
- raises ``BeatDoesNotExist`` on failure, and ``BeatDoesNotExist`` is a
+ ``Beat.objects.get()`` call, because it's not necessary; that function
+ raises ``Beat.DoesNotExist`` on failure, and ``Beat.DoesNotExist`` is a
subclass of ``ObjectDoesNotExist``. Raising ``ObjectDoesNotExist`` in
``get_object()`` tells Django to produce a 404 error for that request.
* To generate the feed's ``<title>``, ``<link>`` and ``<description>``,
@@ -292,7 +293,7 @@ URLconf to add the extra versions.
Here's a full example::
from django.contrib.syndication.feeds import Feed
- from django.models.chicagocrime import newsitems
+ from chicagocrime.models import NewsItem
from django.utils.feedgenerator import Atom1Feed
class RssSiteNewsFeed(Feed):
@@ -301,7 +302,7 @@ Here's a full example::
description = "Updates on changes and additions to chicagocrime.org."
def items(self):
- return newsitems.get_list(order_by=('-pub_date',), limit=5)
+ return NewsItem.objects.order_by('-pub_date')[:5]
class AtomSiteNewsFeed(RssSiteNewsFeed):
feed_type = Atom1Feed
@@ -328,7 +329,6 @@ Feed class reference
This example illustrates all possible attributes and methods for a ``Feed`` class::
-
from django.contrib.syndication.feeds import Feed
from django.utils import feedgenerator