Skip to content

Commit

Permalink
Blog Feed added.
Browse files Browse the repository at this point in the history
  • Loading branch information
AliYmn committed Feb 15, 2017
1 parent f1ac952 commit 4a277a3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion DjangoBlog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from django.contrib import admin
from blog.views import (HomeListView,PostDetailView,
AboutTemplateView,BlogListView,
ContactView,CategoryView,RobotsView,TagsView)
ContactView,CategoryView,RobotsView,TagsView,LatestEntriesFeed)
from django.conf import settings
from django.views.static import serve
from django.contrib.sitemaps import GenericSitemap
Expand Down Expand Up @@ -58,6 +58,7 @@

url(r'^robots.txt/', RobotsView.as_view(), name="robots"),
url(r'^ckeditor/', include('ckeditor_uploader.urls')),
url(r'^latest/feed/$', LatestEntriesFeed()),
]

urlpatterns += [
Expand Down
23 changes: 23 additions & 0 deletions blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,26 @@ def get_context_data(self, **kwargs):
context['category'] = Category.objects.all()
context['tags'] = Tags.objects.all().filter(blog__is_active=True,tags=self.kwargs['slug'])[:1]
return context


from django.contrib.syndication.views import Feed
from django.urls import reverse
from .models import Post

class LatestEntriesFeed(Feed):
title = "Police beat site news"
link = "/sitenews/"
description = "Updates on changes and additions to police beat central."

def items(self):
return Post.objects.order_by('-time')[:5]

def item_title(self, item):
return item.title

def item_description(self, item):
return item.description

# item_link is only needed if NewsItem has no get_absolute_url method.
def item_link(self, item):
return reverse('post', args=[item.url])

0 comments on commit 4a277a3

Please sign in to comment.