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 - last_date_seen
>     else:
>         date_difference = None
> 
>     event_tuples.push((event, date_difference))

In the past I've created something like this as a filter, which lets
it be fairly generic. I also make it a generator rather than keeping
them all around. Something like (I don't have the exact code on hand)

  from django import template
  register = template.base.Library()
  @register.filter(name="pairwise")
  def pairwise(iterable, final=True):
    i = iter(iterable)
    a = next(i)
    for b in i:
      yield a, b
      a = b
    if final:
      yield a, None

-tkc



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20150209214649.4ef17717%40bigbox.christie.dr.
For more options, visit https://groups.google.com/d/optout.

Reply via email to