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