Skip to content

Instantly share code, notes, and snippets.

@chriskief
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriskief/3d2db80d47e42f7620ec to your computer and use it in GitHub Desktop.
Save chriskief/3d2db80d47e42f7620ec to your computer and use it in GitHub Desktop.
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