Ejemplo n.º 1
0
def add_team(request, group_id):
    group = get_object_or_404(Group, pk=group_id)
    if request.method == 'POST':
        if request.POST.getlist('teams') != []:
            for team in request.POST.getlist('teams'):
                t = get_object_or_404(Team, pk=int(team))
                result = TeamResult(team=t)
                result.save()

                group.teams.add(t)
                group.results.add(result)
                group.save()
            messages.success(request, 'Teams added successfully')
        return redirect('soccer.views.group', str(group.id))

    teams = list(set(Team.objects.all()) - set(group.teams.all()))
    return {'teams': teams, 'group': group}
Ejemplo n.º 2
0
def matches_generate_listing(request):
    group = get_object_or_404(Group, pk=request.POST['group_id'])
    teams = list(group.teams.all())

    for team in teams:
        result = TeamResult(team=team)
        result.save()
        group.results.add(result)

    matches = []
    schedule = round_robin(teams)
    for round in schedule:
        for teams in round:
            match = Match(teamA=teams[0], teamB=teams[1], referee=request.user)
            match.save()
            group.matches.add(match)
            matches.append(match)
    return {'matches': matches, 'group': group}