Django makes it relatively easy to combine the information gathered from the order and shipment process into a simple Customer Relationship Management (CRM) tool. We can simply wrap a generic view to display a list of the logged-in user's orders.
@login_required def order_list(request, *args, **kwargs): queryset = Order.objects.filter(customer=request.user) return list_detail.object_list(request, queryset, *args, **kwargs)
This uses the standard Django object_list
generic view we've seen from earlier chapters. A detail view on a specific Order object is equally as simple. We will wrap the list_detail.object_detail
generic view to ensure that only the current user's Order
s can be inspected:
@login_required def order_detail(request, *args, **kwargs): queryset = Order.objects.filter(customer=request.user) return list_detail.object_detail(request, queryset, *args, **kwargs)
At first glance these wrapper views seem superfluous, but they are necessary to ensure that...