From 7e5474ff16dafc45af71b23c2994b5619b0a0ef7 Mon Sep 17 00:00:00 2001 From: TKroenert Date: Sat, 5 Mar 2011 02:29:16 +0100 Subject: [PATCH] Homeseite mit sortierung was am liebsten getrunken wurde --- devel/TODO | 1 + k4ever/main/templates/main/startpage.html | 11 ++++++++++- k4ever/main/views.py | 6 +++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/devel/TODO b/devel/TODO index e47269c..74b8021 100644 --- a/devel/TODO +++ b/devel/TODO @@ -1,6 +1,7 @@ WTFs: [x] Kontostand beim kaufen auch veraendern.. [x] Einkaufshistory basteln +[ ] Beim einkaufen von Objekten ohne Deposit sollten es nicht moeglich sein diese "with Deposit" zu kaufen Noch zu tun: [ ] "Home" mit inhalt fuellen diff --git a/k4ever/main/templates/main/startpage.html b/k4ever/main/templates/main/startpage.html index c2888ce..54335c6 100644 --- a/k4ever/main/templates/main/startpage.html +++ b/k4ever/main/templates/main/startpage.html @@ -1,5 +1,14 @@ {% extends "base.html" %} {% block "content" %} - No content here. + {% if usersMost %} + Am oeftesten hatten alle:

+ {% for buyable in usersMost %} + {{ buyable.buyable__name }} ( {{ buyable.num_buys }} mal)
+ {% endfor %} +
+ {% else %} + {{ error }} + Nix gekauft? + {% endif %} {% endblock %} diff --git a/k4ever/main/views.py b/k4ever/main/views.py index 35ba0ec..3c1d44b 100644 --- a/k4ever/main/views.py +++ b/k4ever/main/views.py @@ -1,10 +1,14 @@ from django.shortcuts import render_to_response from django.template import RequestContext from django.contrib.auth.decorators import login_required +from django.db.models import Count + +from buyable.models import Purchase, Buyable @login_required def startpage(request): - return render_to_response("main/startpage.html", {}, RequestContext(request)) + usersMost = Purchase.objects.values('buyable__name').annotate(num_buys=Count('buyable')).order_by('-num_buys') + return render_to_response("main/startpage.html", {'usersMost': usersMost}, RequestContext(request)) def register(request): return render_to_response("registration/register.html", RequestContext(request))