class FootballUpdate(UpdateView):
model = Football
fields = ['date', 'time', 'duration', 'category', 'place', 'game_status', 'event', 'score_team1', 'score_team2', 'team1', 'team2', 'game_level']
template_name_suffix = '_update_form'
success_url = reverse_lazy('index')
def post(self, request, pk):
match = Football.objects.get(pk=pk)
team1 = match.team1
team2 = match.team2
score_team1 = match.score_team1
score_team2 = match.score_team2
if score_team1 > score_team2:
football_score = FootballScore.objects.filter(team=team1)[0]
football_score.win = football_score.win + 1
football_score.save()
return HttpResponse('Score Successfully Updated! Team1 won!')
else:
football_score = FootballScore.objects.filter(team=team2)[0]
football_score.win = football_score.win + 1
football_score.save()
return HttpResponse('Score Successfully Updated! Team2 won!')
------------------------------------------------------------------------
class Football(Match):
score_team1 = models.IntegerField(default='-1')
score_team2 = models.IntegerField(default='-1')
team1 = models.ForeignKey(Team, related_name='team1_football', on_delete=models.CASCADE, null=True)
team2 = models.ForeignKey(Team, related_name='team2_football', on_delete=models.CASCADE)
game_level = models.CharField(max_length=256, null=True, choices=LEVEL_CHOICES) # like semi-final, final etc
# connect = models.ForeignKey(Match, on_delete=models.CASCADE)
def __str__(self):
return str(self.game_level)
class FootballScore(models.Model):
team = models.ForeignKey(Team, related_name='teams', on_delete=models.CASCADE)
win = models.IntegerField(default='0')
我的运动是足球和它通常的领域,现在我正在使足球得分,以更新球队的获胜领域。如你所见,我之前已经为足球模型做了updateview,现在我正在对它进行修改,以添加我的新要求,增加win field,以前updateview工作正常,添加“win”field后,我的win field在增加fine,但update field不工作。谢谢。