Venor
Venor

Reputation: 347

Refreshing displayed data

I have this view working and displaying everything correctly. Though when I update the db the displayed data doesn't update in the view.

By restarting the httpd server it then updates the displayed data.

from django.views.generic import ListView
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import render_to_response
from player.models import .

list = [123,155,166,445]

class Stats(LoginRequiredMixin, ListView):
    model = Table
    template_name   = 'stats.html'    
    object_list     = Table.objects.all()    
    data            = object_list.filter(id__in= list)    
    contract        = [x.Contract for x in data]    
    will            = [x.Will for x in data]

    def get(self, request,):
        context                       = locals()
        context['contract']           = self.contract.count('Deed1')
        context['will']               = self.will.count('Death')
        return render_to_response(self.template_name, context)

I was hoping to get it to display the new count anytime the page refreshes. Any nudge in the right direction greatly appreciated.

Upvotes: 0

Views: 41

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599600

You mustn't operate on models in the definition of the class itself; that'll only be executed once, when the class is first imported. You should do things like that in a method within the class. This should be get_context_data; and in fact you should move those other operations there too, you should not override get().

Upvotes: 1

Related Questions