Skip to content

Instantly share code, notes, and snippets.

@douglasmiranda
Created June 18, 2012 00:44
Show Gist options
  • Save douglasmiranda/2946192 to your computer and use it in GitHub Desktop.
Save douglasmiranda/2946192 to your computer and use it in GitHub Desktop.
from django.views.generic import View
from django.template.response import TemplateResponse
from news.models import Noticia
from videos.models import Video
from datetime import datetime
class HomeView(View):
template_name = 'home/home.html'
def get(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
return TemplateResponse(
request=self.request,
template=self.template_name,
context=context,
**kwargs
)
def get_context_data(self, **kwargs):
context = {}
context['noticias_em_destaque'] = Noticia.objects.destaques()[:7]
context['videos'] = Video.objects.filter(publicacao__lte=datetime.now())[:4]
return context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment