0

I'm trying to pass a Sum to my ListView. But if I add more to the DB the Sum does not change until I restart Apache. The new objects are appearing in the List. What am I missing? It seems to get cached for some reason.

class ReceiptListView(ListView):
    model = Receipt
    total_amount = Receipt.objects.all().aggregate(Sum('amount'))
    extra_context = {"total_amount":total_amount["amount__sum"],} 
    def get_context_data(self, **kwargs): 
        context = super(ReceiptListView, self).get_context_data(**kwargs)
        context.update(self.extra_context)
        return context
JasonTS
  • 2,479
  • 4
  • 32
  • 48

1 Answers1

0

Why are you defining those values at class level? That way they will only be evaluated once.

Move them into the get_context_data method where they are used.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895