Changeset 299 for django_apps


Ignore:
Timestamp:
Apr 7, 2011, 6:07:28 PM (14 years ago)
Author:
Rick van der Zwet
Message:

Week totals

File:
1 edited

Legend:

Unmodified
Added
Removed
  • django_apps/running/views.py

    r298 r299  
    4242    user = get_object_or_404(User, pk=user_id)
    4343    result_list = Result.objects.filter(user=user).values_list('date', 'distance')
     44
     45    total_list = {}
     46    for (date,distance) in result_list:
     47       key = date.strftime("%Y-%m")
     48       if total_list.has_key(key):
     49         total_list[key] += distance
     50       else:
     51         total_list[key] = distance
     52
    4453    json_object = { 'label' : [] , 'data' : [] }
    45     for (date,distance) in result_list:
    46        json_object['label'].append(str(date))
     54    for (date,distance) in total_list.iteritems():
     55       json_object['label'].append(date)
    4756       json_object['data'].append(float(distance))
    4857    data = json.dumps(json_object, ensure_ascii=False, indent=2)
Note: See TracChangeset for help on using the changeset viewer.