def testMatchLogics(self): team1 = Team(short_name="SP", full_name="São Paulo FC") team2 = Team(short_name="Palmeiras", full_name="Palmeiras FC") team1.save() team2.save() season = Season(start_year=2012, end_year=2012) season.save() cp = Championship(name="Brasileirao", start_date=timezone.now()) cp.season = season cp.save() match1 = Match() match1.championship = cp match1.home_team = team1 match1.away_team = team2 match1.match_date = timezone.now() match1.save()
def winner_prediction(request): winner_coef_data = WinnerPredictionCoef.objects.all().select_related( 'team_id').order_by('coef') curr_prediction = WinnerPrediction.objects.filter( user_id=request.user.id).first() if request.method == 'POST': frm = WinnerPredictionForm(request.POST) team_id = request.POST['team_id'] if frm.is_valid(): WinnerPrediction.objects.update_or_create( user_id=request.user, defaults={'team_id': Team(team_id=team_id)}) return redirect('home') else: frm = WinnerPredictionForm() return render( request, 'winner.html', { 'winner_coef': winner_coef_data, 'curr_prediction': curr_prediction, 'submissions_closed': datetime.now(pytz.UTC) > COMPETITION_START_DATE_UTC, 'form': frm })