Last active
November 29, 2016 13:59
-
-
Save craigderington/eb42566f220597416c52 to your computer and use it in GitHub Desktop.
CustomerListView - Generic List View with Django Tables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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