代码发芽网做RSS的两个类,Django做RSS真方便

切换背景色
主题: 字体: 切换行号 全选代码块(Ctrl+C复制) 半瓶墨水1年前贴出, Python 语言
Python代码: 代码发芽网做RSS的两个类,Django做RSS真方便
01 #coding=utf-8
02 #参照: http://www.djangoproject.com/documentation/syndication_feeds/
03
04 from django.contrib.syndication.feeds import Feed
05 from fayaa.coding.models import Codee, CodeeComment
06
07 class LatestCodees(Feed):
08     title = "代码发芽网最新代码"
09     link = "/code/feeds/codees/"
10     description = "来自代码发芽网( http://www.fayaa.com/code/ )的最新代码"
11
12     def items(self):
13         return Codee.objects.order_by('-create_time')[:15]
14
15     def item_link(self, item):
16         return "http://www.fayaa.com/code/view/%d/" % item.id
17
18 class LatestComments(Feed):
19     title = "代码发芽网最新评论"
20     link = "/code/feeds/comments/"
21     description = "来自代码发芽网(http://www.fayaa.com/code/)的最新评论"
22
23     def items(self):
24         return CodeeComment.objects.order_by('-create_time')[:15]
25
26     def item_link(self, item):
27         return "http://www.fayaa.com/code/view/%d/" % item.codee.id
返回正常查看模式 返回代码发芽网首页