Skip to content

Instantly share code, notes, and snippets.

@craigderington
Last active November 29, 2016 13:59
Show Gist options
  • Save craigderington/eb42566f220597416c52 to your computer and use it in GitHub Desktop.
Save craigderington/eb42566f220597416c52 to your computer and use it in GitHub Desktop.
CustomerListView - Generic List View with Django Tables
from django.views.generic import ListView
from braces.views import LoginRequiredMixin, GroupRequiredMixin
from django_tables2 import RequestConfig
from .models import Customer
from .tables import CustomerTable
class CustomerListView(LoginRequiredMixin, GroupRequiredMixin, ListView):
model = Customer
template_name = 'customer_list.html'
context_object_name = 'customer'
ordering = ['id']
group_required = u'company-user'
def get_context_data(self, **kwargs):
context = super(CustomerListView, self).get_context_data(**kwargs)
context['nav_customer'] = True
table = CustomerTable(Customer.objects.filter(self.kwargs['company']).order_by('-pk'))
RequestConfig(self.request, paginate={'per_page': 30}).configure(table)
context['table'] = table
return context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment