def new_group(request): competition = None if 'competition' in request.GET: competition = get_object_or_404(Competition, pk=int(request.GET['competition'])) if 'competition' in request.POST: competition = get_object_or_404(Competition, pk=int(request.POST['competition'])) if request.method == 'POST': form = NewEventForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] group = Group(name=name) group.save() competition.groups.add(group) competition.save() msg = "New group {0} has been created!".format(name) messages.success(request, msg) return redirect('soccer.views.group', str(group.id)) else: form = NewEventForm() c = {} c.update(csrf(request)) c['form'] = form if competition: c['competition'] = competition else: c['competitions'] = Competition.objects.all() return c
def new_competition(request): event = None if request.method == 'POST': form = NewEventForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] competition = Competition(name=name) competition.save() msg = "New competition {0} has been created!".format(name) messages.success(request, msg) return redirect('soccer.views.competition', str(competition.id)) else: form = NewEventForm() c = {} c.update(csrf(request)) c['form'] = form return c