views:

101

answers:

1

Hello, I have model with following field.

date = models.DateTimeField(auto_now_add=True)

When querying such model i`d like to have additional column that would keep difference between current date and previous one. So for 10 rows it would have 9 values, first one would be None. Are there any ways of achieving this with querysets? or maybe i should mess around and create additional list that would hold such differences before i pass queryset to template? Please advise.

+1  A: 

Create a property on the model that calls get_ {next,previous}_ by_*() and returns the timedelta. For advanced functionality, implement caching.

Ignacio Vazquez-Abrams
Great advice. One queryset and it works. Thanks !
MichalKlich