1

I am currently using django-reversion to track a model Account which has a field total_spent.

Overtime this field gets updated whenever an accounts spends money. My goal is to retrieve the value of total_spent between X and Y, which are both datetime instances.

How can I do so efficiently?

Tinker
  • 4,165
  • 6
  • 33
  • 72

2 Answers2

1

You'd have something like this: given you have a Django model and two time fields, get their elapsed time difference:

class SomeModel(models.Model):
    start_time = models.DateTimeField(blank=True, null=True)
    end_time = models.DateTimeField(blank=True, null=True)

    @property
    def total_spent(self):
        return self.end_time - self.start_time

and then use total_spent as yet another property of that model.

dmitryro
  • 3,463
  • 2
  • 20
  • 28
0

You would need to know the value in both instances. For that you have to store total_spent every time it updates.

D. Vargas
  • 58
  • 5