filter matches by name

clubs
Laurent 2 years ago
parent 49c7cff126
commit 7d23fa68d0
  1. 7
      tournaments/models/tournament.py
  2. 2
      tournaments/templates/tournaments/broadcasted_matches.html
  3. 4
      tournaments/views.py

@ -68,7 +68,7 @@ class Tournament(models.Model):
return summons return summons
def live_matches(self): def live_matches(self, broadcasted):
matches = [] matches = []
for group_stage in self.groupstage_set.all(): for group_stage in self.groupstage_set.all():
for match in group_stage.match_set.all(): for match in group_stage.match_set.all():
@ -77,8 +77,11 @@ class Tournament(models.Model):
for match in round.match_set.all(): for match in round.match_set.all():
matches.append(match) matches.append(match)
if broadcasted:
matches = [m for m in matches if m.broadcasted==True] matches = [m for m in matches if m.broadcasted==True]
# matches = [m for m in matches if len(m.team_scores.all()) > 0] if not broadcasted:
matches = [m for m in matches if len(m.team_scores.all()) > 0]
matches.sort(key=lambda m: m.order) matches.sort(key=lambda m: m.order)
return [match.live_match() for match in matches] return [match.live_match() for match in matches]

@ -70,7 +70,7 @@
<div class="flex-row"> <div class="flex-row">
<label class="left-label matchtitle"><span x-text="match.title"></span></label> <label class="left-label matchtitle"><span x-text="match.title"></span></label>
<label class="right-label info"><span x-text="match.date"></span></label> <!-- <label class="right-label info"><span x-text="match.date"></span></label> -->
</div> </div>
<template x-for="i in match.teams.length"> <template x-for="i in match.teams.length">

@ -36,7 +36,7 @@ def index(request):
def tournament(request, tournament_id): def tournament(request, tournament_id):
tournament = get_object_or_404(Tournament, pk=tournament_id) tournament = get_object_or_404(Tournament, pk=tournament_id)
live_matches = list(tournament.live_matches()) live_matches = list(tournament.live_matches(broadcasted=False))
return render(request, 'tournaments/matches.html', { return render(request, 'tournaments/matches.html', {
'tournament': tournament, 'tournament': tournament,
'matches': live_matches, 'matches': live_matches,
@ -78,7 +78,7 @@ def tournament_matches(request, tournament_id):
def tournament_matches_json(request, tournament_id): def tournament_matches_json(request, tournament_id):
tournament = get_object_or_404(Tournament, pk=tournament_id) tournament = get_object_or_404(Tournament, pk=tournament_id)
live_matches = tournament.live_matches() live_matches = tournament.live_matches(broadcasted=True)
data = json.dumps(live_matches, default=vars) data = json.dumps(live_matches, default=vars)
return HttpResponse(data, content_type='application/json') return HttpResponse(data, content_type='application/json')

Loading…
Cancel
Save