Month: March 2018

Django DetailView with pagination for related objects

This is an example of a DetailView of a User that can have a paginated list of Purchases: from django.views.generic.detail import DetailView from django.core import paginator @method_decorator(staff_member_required(login_url=’user_login’), name=’dispatch’) class UserDetailView(DetailView): model = User template_name = “user_detail.html” purchases_paginate_by = 5 def get_context_data(self, **kwargs): context = super(UserDetailView, self).get_context_data(**kwargs) purchases_page = self.request.GET.get(“purchases_page”) purchases = self.object.get_purchases().filter() purchases_paginator = paginator.Paginator(purchases, Read More

Export object_list of a django-filters FilterView to CSV

This is a simple way to allow users to export the data they have just filtered using django-filterĀ as CSV. # Normal View (has a link to export view and keeps GET parameters) @method_decorator(staff_member_required(login_url=’user_login’), name=’dispatch’) class PaymentListView(FilterView): filterset_class = filters.PaymentFilter template_name = “barsys/userarea/payment_list.html” paginate_by = 10 # Export View @method_decorator(staff_member_required(login_url=’user_login’), name=’dispatch’) class PaymentExportView(FilterView): filterset_class = filters.PaymentFilter Read More

Running multiple Django projects on one Apache instance with mod_wsgi

I did not yet find a page with a concise but complete description of how to run multiple Django instances/projects on one server with Apache. This method is similar to the one in the Django docs, but the docs version does not run the Django instance in a daemon process, therefore it does not work Read More