Take the 2-minute tour ×

I am building a shop kiosk in django and I have a view that displays some sold products within a time range like so;

def product_sold_report(request):
    response = {}
    id_list = []
        _start = _get_parameter(request, "_start")
    except Exception, e:
        _start = None

        _end = _get_parameter(request, "_end")
    except Exception, e:
        _end = None

    if _start and _end:
        orders = Order.objects.filter(created__range=[datetime.datetime.fromtimestamp(float(_start)),datetime.datetime.fromtimestamp(float(_end))]).filter(status = 4).order_by("-created")
        orders = Order.objects.all().filter(status=4).order_by("-created")

    for order in orders:

    for item in OrderItem.objects.filter(order__in = id_list):
        i = Order.objects.get(id = item.order_id)
            product = Product.objects.get(id = item.product_reference)
            barcode = product.barcode
        except Exception,e:
            barcode = None

        if item.product_name in response:
            response[item.product_name]["product_quantity"] += item.quantity
            response[item.product_name] = {


    return HttpResponse(simplejson.dumps(response), mimetype="text/json")


However, I want to use a rest framework so that I can have a different web app on another server query this app and get the same products sold results , I have considered django tastypie but it seems to major a lot on models resources. Is it possible to have this done using django tastypie or django rest framework.


share|improve this question

1 Answer 1

up vote 0 down vote accepted

You don't NEED a full restful service to get the same results. As long as your views are returning well formed JSON data - Just use good URL patterns in your url.py that maps to your view functions.

You can craft URL patterns just like tastypie /api/v1/products_sold/ Just work with some regex - and make sure the URLS just make sense

share|improve this answer
Thanks a lot Hacking Life for the answer, i think i will do exactly that because i cant really find a way to get django tastypie return the data i would like. By the way do you think writing the custom views will have any performance issues? Thanks –  Muhia NJoroge Jan 25 '13 at 17:47
Not if you make sure your Queries are efficient. Make sure when working with your data that you hit the data with what you need ONCE, then perhaps look into things like parsing through a data dictionary that's returned. The less you hit the server for additional info the better –  Hacking Life Jan 25 '13 at 19:32

Your Answer


