filter matches by name

clubs
Laurent 2 years ago
parent 49c7cff126
commit 7d23fa68d0
  1. 9
      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
def live_matches(self):
def live_matches(self, broadcasted):
matches = []
for group_stage in self.groupstage_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():
matches.append(match)
matches = [m for m in matches if m.broadcasted==True]
# matches = [m for m in matches if len(m.team_scores.all()) > 0]
if broadcasted:
matches = [m for m in matches if m.broadcasted==True]
if not broadcasted:
matches = [m for m in matches if len(m.team_scores.all()) > 0]
matches.sort(key=lambda m: m.order)
return [match.live_match() for match in matches]

@ -70,7 +70,7 @@
<div class="flex-row">
<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>
<template x-for="i in match.teams.length">

@ -36,7 +36,7 @@ def index(request):
def tournament(request, 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', {
'tournament': tournament,
'matches': live_matches,
@ -78,7 +78,7 @@ def tournament_matches(request, tournament_id):
def tournament_matches_json(request, 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)
return HttpResponse(data, content_type='application/json')

Loading…
Cancel
Save