Skip to content

Instantly share code, notes, and snippets.

@craigderington craigderington/views.py
Last active Nov 29, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.