Changeset 2766
- Timestamp:
- 04/28/06 00:05:56 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/magic-removal/docs/syndication_feeds.txt
r2700 r2766 94 94 95 95 from django.contrib.syndication.feeds import Feed 96 from django.models.chicagocrime import newsitems96 from chicagocrime.models import NewsItem 97 97 98 98 class SiteNewsFeed(Feed): … … 102 102 103 103 def items(self): 104 return newsitems.get_list(order_by=('-pub_date',), limit=5)104 return NewsItem.objects.order_by('-pub_date')[:5] 105 105 106 106 Note: … … 177 177 if len(bits) != 1: 178 178 raise ObjectDoesNotExist 179 return beats.get_object(beat__exact=bits[0])179 return Beat.objects.get(beat__exact=bits[0]) 180 180 181 181 def title(self, obj): … … 189 189 190 190 def items(self, obj): 191 return crimes.get_list(beat__id__exact=obj.id, order_by=(('-crime_date'),), limit=30)191 return Crime.objects.filter(beat__id__exact=obj.id).order_by('-crime_date')[:30] 192 192 193 193 Here's the basic algorithm the RSS framework follows, given this class and a … … 205 205 ``django.core.exceptions.ObjectDoesNotExist`` if given invalid 206 206 parameters. There's no ``try``/``except`` around the 207 `` beats.get_object()`` call, because it's not necessary; that function208 raises ``Beat DoesNotExist`` on failure, and ``BeatDoesNotExist`` is a207 ``Beat.objects.get()`` call, because it's not necessary; that function 208 raises ``Beat.DoesNotExist`` on failure, and ``Beat.DoesNotExist`` is a 209 209 subclass of ``ObjectDoesNotExist``. Raising ``ObjectDoesNotExist`` in 210 210 ``get_object()`` tells Django to produce a 404 error for that request. … … 294 294 295 295 from django.contrib.syndication.feeds import Feed 296 from django.models.chicagocrime import newsitems296 from chicagocrime.models import NewsItem 297 297 from django.utils.feedgenerator import Atom1Feed 298 298 … … 303 303 304 304 def items(self): 305 return newsitems.get_list(order_by=('-pub_date',), limit=5)305 return NewsItem.objects.order_by('-pub_date')[:5] 306 306 307 307 class AtomSiteNewsFeed(RssSiteNewsFeed): … … 329 329 330 330 This example illustrates all possible attributes and methods for a ``Feed`` class:: 331 332 331 333 332 from django.contrib.syndication.feeds import Feed
