def create_team(request, tournament_id): tournament = Tournament.objects.get(pk=int(tournament_id)) # if this is a POST request we need to process the form data if request.method == "POST": # create a form instance and populate it with data from the request: form = TeamForm(request.POST) # check whether it"s valid: if form.is_valid(): team = Team.create(form.cleaned_data["name"], tournament) for player_name in form.cleaned_data["members"].split(","): summoner = Summoner.find_or_create(player_name) team.summoners.add(summoner) return redirect('tournament', tournament_id=tournament_id) else: form = TeamForm() return render(request, "team/create.html", {"form": form, "action":reverse("create_team", args=[tournament.id])})