score:0

Accepted answer

based on your input, i guess first request is calling home view and loads initial set data - which is then displayed on html page. on the other hand, then you are using chartdata api view. if this scenario is right - then:

the problem in chartdata is that, this part time, set1 , set2 , set3 = get_sets() is executed one time when django is initialized (as described). what you need is to get sets each time when request is sent. and the code fragment is executing upon request is in get method.

right solution would look like this:

class chartdata(apiview):
   authentication_classes = []
   permission_classes = []
   sets = sets.objects.all()

   def get(self, request, format=none):
      time, set1 , set2 , set3 = get_sets()

      data = {
        "time": time,
        "set1": set1,
        "set2": set2,
        "set3": set3
       }

       return response(data)

there is no need for extra class variables (self.set1 ...). and the get_sets function is called each time request reaches the get method.

update (based on comment)

to avoid loading whole data each time request is handled by api view - i would keep track of last record received in frontend and based on last record id (there may be another field) i would fetch records created after the id you're tracking in frontend.


Related Query

More Query from same tag