I have a football Team class in my django Model. I made 3 methods of win, draw and lose where the self.Points_of_the_season will be modified accordingly ( +3 for win, +1 for draw and +0 for lose). But when I wrote those methods, I have to change the self.Match_Played with each call of the 3 methods. How can I make a decorator called @play_match which will add 1 to the concerned field?
This is the code of models.py:
class Team(models.Model):
Team_name = models.CharField(max_length=255)
Foundation_year = models.IntegerField()
Points_of_season = models.IntegerField(default=0)
Match_Played = models.IntegerField(default=0)
League = models.ForeignKey(League, on_delete=models.CASCADE)
def __str__(self):
return f"{self.Team_name}-{self.Foundation_year}"
@play_match
def win(self):
self.Points_of_season += 3
@play_match
def draw(self):
self.Points_of_season += 1
@play_match
def lose(self):
pass