Commits

Tibor Tóth committed 606d57a

Fixed bar chart indexing.

Comments (0)

Files changed (1)

     expense_type =  models.Type.objects.get(id = type)
     data =  _get_chart_data(expense_type, user_id, year, month)
     labels =  []
-    for c in expense_type.categories.all():
-        labels.append([c.id, c.name])
+    index = 0
+    for c in expense_type.categories.all().order_by('name'):
+        labels.append([index, c.name])
+        index = index + 1
     
     t = loader.get_template('admin/expense/expense/charts.html')
     c = Context({
     for u in users:
         user_data = []
         user_filter =  q & Q(user = u)
-        for c in type.categories.all():
+        index = 0
+        for c in type.categories.all().order_by('name'):
             sub_total = c.expenses.filter(user_filter).aggregate(
                 total = Sum('amount'))
 
             if(sub_total["total"]):
-                user_data.append([c.id, sub_total["total"]])
+                user_data.append([index, sub_total["total"]])
             else:
-                user_data.append([c.id, 0])
-            
+                user_data.append([index, 0])
+
+            index = index + 1
         results.append({'label': u.username, 'data': user_data})
 
-#    data = t.categories.filter(q).annotate(category_total =
-#                                           Sum('expenses__amount'))
-
-    #total = t.category_list.aggregate(total = Sum('category_total'))
-    #  t.total =  total['total']
     return results