def edit_league_info(request, league_id): league = get_object_or_404(League, pk=league_id) league_form = LeagueForm(instance=league) if request.method == 'POST': league_form = LeagueForm(request.POST, instance=league) if league_form.is_valid(): league = league_form.save() return HttpResponseRedirect(reverse('basketball:league-info', args=[league.pk])) context = {'league_form': league_form, 'league': league} return render(request, 'basketball/edit_league.html', context)
def create_league(request): if request.method == 'GET': league_form = LeagueForm() context = {'league_form': league_form} elif request.method == 'POST': league_form = LeagueForm(request.POST) if league_form.is_valid(): league = league_form.save() return HttpResponseRedirect(reverse('basketball:league-info', args=[league.pk])) else: context = {'league_form': league_form} return render(request, 'basketball/create_league.html', context)