A simple CRM tool

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 Orders 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 the user who is logged-in can see only their own orders and no others. The Django generic view framework makes this easy, of course, by allowing us to pass the same filtered queryset in both instances. This requires wrapping in our own view code and cannot be defined in the URL pattern, because the request object is unavailable. We must have access to request to obtain the logged-in user.

With the list and detail views in place, we can write simple templates, as we did for our Product catalog. Because only site administrators and the customer can access the details for their order, we could use Django's comments framework, again, to implement a very simple customer feedback feature. Customer feedback is a primary concern of CRM tools.

The comments framework may lack a complete set of functionality for serious CRM applications, but it provides a simple, reasonably secure channel of feedback on a per-order basis. It could also be easily extended or a substitute could be put in place using the same "pluggable app" design that Django's comments exemplifies.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset