2👍
Agreed with the comments that more detail would be helplful.
However, in lieu of that, one thought would be to take those calculations and turn them into model fields. For example, if the objects you’re looping through are a model called Rectangle as in the below:
class Rectangle(models.Model):
name = models.CharField()
side1 = models.IntegerField()
side2 = models.IntegerField()
And you want to spit out a Excel file with the area and perimeter of each Rectangle, you could add two more fields:
area = models.IntegerField()
perimeter = models.IntegerField()
And calculate those as the Rectangles are created as opposed to what you’re doing now where you calculate them as you make an Excel sheet. For the items you already have you can then update the models for the new fields and then write a script to do a one-time calculation to populate them.
This way you can just call
Rectangle.objects.all().values('name', 'area', 'perimeter')
to get just what you want.
Source:stackexchange.com