-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
40 lines (31 loc) · 1.06 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from django.shortcuts import render
from django.shortcuts import get_object_or_404
from civ_5_tracker.models import Game
from civ_5_tracker.models import Player
# from civ_5_tracker.models import Victor
def games(request):
games = Game.objects.all()
return render(request, "games.html", {"games": games})
def players(request):
players = Player.objects.all()
context = {
"players": players,
}
return render(request, "players.html", context)
def player(request, player_name):
player = get_object_or_404(Player, name=player_name)
wins = player.victor_set.all()
win_count = wins.count()
games = player.participant_set.all()
game_count = games.count()
context = {
"player": player,
"wins": wins,
"win_count": win_count,
"game_count": game_count
}
return render(request, "player.html", context)
def victories(request):
games = Game.objects.filter(victor__in=Player.objects.all())
# players = Player.objects.all()
return render(request, "victories.html", {"games": games})