def statistics_page(request): import datetime c = get_common_context(request) c['title'] = u'Статистика аккаунта' if request.method == 'POST': try: date_from = datetime.datetime.strptime(request.POST.get('date_from', ''),'%d.%m.%Y') date_to = datetime.datetime.strptime(request.POST.get('date_to', ''),'%d.%m.%Y') except: messages.error(request, u'Необходимо выбрать даты') return HttpResponseRedirect('/cabinet/statistics/') if date_from > date_to: dd = date_from date_from = date_to date_to = dd funfics = Work.get_by_author(request.user) c['date_from'] = date_from.strftime('%d.%m.%Y') c['date_to'] = date_to.strftime('%d.%m.%Y') td = datetime.timedelta(days=1) result = [] curr = date_from while curr <= date_to: stat = [] for f in funfics: print curr, f.id, Review.get_count_by_work_date_range(f, curr, curr+td) curr_stat = { 'funfic': f, 'reviews': Review.get_count_by_work_date_range(f, curr, curr+td), 'comments': Comment.get_count_by_work_date_range(f, curr, curr+td), 'bookmarks': Bookmark.get_count_by_work_date_range(f, curr, curr+td), } curr_stat.update(Rating.get_count_by_work_date_range(f, curr, curr+td)) stat.append(curr_stat) result.append((curr.date(), stat)) curr = curr + td c['statistics'] = result return render_to_response('cabinet/statistics.html', c, context_instance=RequestContext(request))