models.py
class ModFile(models.Model):
mod = models.ForeignKey(Mod, on_delete=models.CASCADE)
title = models.CharField(max_length=128)
downloads = models.IntegerField(default=0)
file = models.FileField(upload_to='mods/')
views.py
class downloadMod(APIView):
def get(self, request, id):
file = models.ModFile.objects.get(id=id)
file.downloads += 1
file.save()
return FileResponse(file.file)
In views.py, the get() function retrieves the model by its id and should increment file.downloads by 1 but for some reason it increments by 2, what am I doing wrong?