Re: models, peeking to next record - maybe

2015-02-09 Thread Tim Chase
On 2015-02-07 22:05, Vijay Khemlani wrote: > The direct solution would be something like this in your view > > events = Event.objects.order_by('event_date') > > event_tuples = [] > last_date_seen = None > > for event in events: > if last_date_seen: > date_difference = event.date -

Re: models, peeking to next record - maybe

2015-02-08 Thread Thomas Rega
Alternatively use the 'latest()' method of the django ORM to figure out which is the latest event: https://docs.djangoproject.com/en/1.7/ref/models/querysets/#latest 2015-02-08 2:05 GMT+01:00 Vijay Khemlani : > The direct solution would be something like this in your view > >

Re: models, peeking to next record - maybe

2015-02-07 Thread Vijay Khemlani
The direct solution would be something like this in your view events = Event.objects.order_by('event_date') event_tuples = [] last_date_seen = None for event in events: if last_date_seen: date_difference = event.date - last_date_seen else: date_difference = None

Re: models, peeking to next record - maybe

2015-02-07 Thread Lachlan Musicman
My initial suggestion would be to utilise the "order by" option, and order by date. Then, on each model have a find_next function and a until_next function. The first would work out which was the next event, the other the time. They could be coupled, but keeping them separate means you can

models, peeking to next record - maybe

2015-02-07 Thread Richard Bowden
Got an problem that I am struggling to solve.. I have: class Address(models.Model): name = models.CharField() event_date = models.DateTime() event1, 25/01/2015 event2, 27/01/2015 event3, 05/02/2015 and so on… what I am trying to figure out is, how to calculate the days between each event.

models, peeking to next record - maybe

2015-02-07 Thread Richard Bowden
I am working on a problem that I am trying to figure out, not having much luck so far... I have a model, basic for this example: class Event(models.Model): name = models.Charfield(max_length=10) event_date = models.DateTime() I am trying to workout how I can calculate the number of days