Creating value historic API logic
===

Consider these pseudo models:


    class Brand(models.Model):
        name = models.CharField()
    
    class Car(models.Model):
        brand = models.ForeignKey(Brand)
        year = models.IntegerField(max_length=4)
    
    class Price(models.Model):
        car = models.ForeignKey(Car)
        value = models.DecimalField()
        date = models.DateTimeField(auto_now=True)

I have setup a price historic resource (using Tastypie) that works on Car.objects.all() and represents data like this:

    {
        data: [
            [1324205148000, 21235],
            [1341062586000, 23532],
            [1343654394000, 34623]
        ],
        name: "Audi 2007"
    },

So the car field is represented by `car__brand__title` combined with `car__year` and data is a list representation with a UNIX timestamp (multiplied by a thousand for JS) followed by an Integer representation of the value.

So far so good, next step;

I want to refactor the resource to be able to combine price historic evaluation for entries where the `car__brand` and `car__year` are equal.

So let's say I have these Car objects:

    ID 1 | Audi    | 2005
    ID 2 | Audi    | 2005
    ID 3 | Renault | 2004

And these Price objects:

    ID 1 | CAR_ID 1    | 10000 | timestamp
    ID 2 | CAR_ID 1    | 12500 | timestamp
    ID 3 | CAR_ID 2    | 15000 | timestamp
    ID 4 | CAR_ID 3    |  9000 | timestamp

I would like my resource to combine these and represent the data like this:

    {
        data: [
            [unix_timestamp, 10000],
            [unix_timestamp, 12500],
            [unix_timestamp, 15000]
        ],
        name: "Audi 2005"
    },
        data: [
            [unix_timestamp, 9000]
        ],
        name: "Renault 2004"
    },

Since Tastypie uses a QuerySet object to create output, I was wondering if this is possible without dehydration cycles using advanced ORM techniques. This might be a silly thought, I don't really know how it would be able to collapse values from one model instance to another. Ofcourse this can be achieved with a dehydrate cycle using list comprehension, but I like seeking alternatives

Any thoughts?