I would like to know how to add all the data in a column of my database.
This is my model:
models.py
class Model(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
id = models.AutoField(primary_key=True)
number = models.FloatField(default=0)
created = models.DateTimeField(auto_now_add=True, null=True)
I would like to obtain the sum of all the data in the number field to then perform an operation, the methods I know are the following but I do not know how to use them:
obj.aggregate(Sum('number')
I want to do something like that but I do not know how to apply it:
obj = Model.objects.all().filter(user=request.user)
obj.number
variable_1 = 10
variable_1 = 10 + obj.number # La suma de todos los registros del campo number
thank you very much friends