Skip to content

Instantly share code, notes, and snippets.

@chriskief

chriskief/view.py

Last active Aug 29, 2015
Embed
What would you like to do?
from django.views.generic import ListView
from django.template.defaultfilters import pluralize
from myapp.models.Product
class MyView(ListView):
queryset = Product.objects.all()
template_name = 'product.html'
context_object_name = 'products'
def get_context_data(self, **kwargs):
context = super(MyView, self).get_context_data(**kwargs)
context['title'] = len(context['products']) + ' Product' + pluralize(context['products']) + ' Found'
return context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment