'How to save data from a webpage into Django database without using a form?

I am trying to save data from my webpage into my Django database. The data does not come from a form - I have built a web-based game with a timer and I would like to store the end value of the timer in my database for each game once the user presses the 'finish' button. The data doesn't come from a form as the timer increments automatically every second and stops when the finish button is pressed - how would i go about saving this to my django database?

this is what the django model looks like:

class Games(models.Model):
    username = models.ForeignKey(User, on_delete=models.CASCADE)
    startTime = models.DateTimeField(auto_now_add=True)
    solveTime = models.IntegerField()
    hintsCount = models.IntegerField()
    difficultyChoices = [
        ('E', 'easy'),
        ('M', 'medium'),
        ('H', 'hard')
    ]
    difficulty = models.CharField(max_length=2, choices=difficultyChoices, default='M')

so for example i would like to be able to send a POST request to the server with {timer: 300, hints:2} which can then be saved with the above model

thanks :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source