Advertisement
SalahAdDinYusuf

Vistas Tema

Aug 1st, 2014
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. import json
  2.  
  3. from django.shortcuts import render, get_object_or_404
  4. from django.http import HttpResponse,Http404, HttpResponseRedirect
  5. from django.views.generic import DetailView, ListView, DateDetailView, MonthArchiveView, WeekArchiveView
  6.  
  7. from actions import week_range
  8. import datetime
  9.  
  10. from .models import Topic
  11. from news.models import New
  12.  
  13. #Mixin
  14. class MenuMixin(object):
  15.     def get_context_data(self, **kwargs):
  16.         today = datetime.date.today()
  17.         context = super(MenuMixin, self).get_context_data(**kwargs)
  18.         context['latest'] = self.model.objects.all()[:20]
  19.         context['local'] = self.model.objects.filter(subtopic__name='Local')[:20]
  20.         context['featured'] = self.model.objects.order_by('-times_viewed').filter(created_date__month=today.month)[:20]
  21.         return context
  22.  
  23. # Create your views here.
  24.  
  25. #Vista basica para Tema
  26. class TopicNewsViews(ListView):
  27.     template_name = 'topic_news.html'
  28.     paginate_by = 10
  29.     model = Topic
  30.     name_field = 'name'
  31.  
  32.     def get_queryset(self):
  33.         name_field='name'
  34.         return self.objects.news.all()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement