Hi guys,
<https://stackoverflow.com/posts/67578113/timeline>

*In order to plot a chart with Highcharts I have to structure a queryset in 
a list of dictionaries that have to look like the following:*
[{ name: 'Europe', data: [{ name: 'Germany', value: 767.1 }, { name: 
"Cyprus", value: 7.2 }] }, { name: 'Africa', data: [{ name: "Senegal", 
value: 8.2 }, { name: "Ghana", value: 14.1 }] }] 

*The following code is the way I tried. The data is structured as requested 
and the graph is plotted good, but the final list (listsocios) is missing 
some values and repeating another ones. I guess it is memory issue. Whats 
your thoughs? Whats would be the more effecient way to struct?*

class GraphSociosProvinciasView(TemplateView):
    template_name = 'socios/socios_prov_graph.html'
    def get_context_data(self,*args, **kwargs):
        context = super(GraphSociosProvinciasView, 
self).get_context_data(*args,**kwargs)
        listsocios=[]
        listsocprov=[]
        #Por cada provincia guardo los socios
        for n in range(1,25):
            sociosp=Socios.objects.filter(provincia=n)
            TotalSocios=sociosp.count()
            listsocprov.clear()
            if TotalSocios!=0:
                for socp in sociosp:
                    listsocprov.append({'name': socp.apellido,'value': 
socp.numero_socio},)
                    nombre_provincia=socp.get_provincia_display()
                listsocios.append({'name':nombre_provincia,'data':listsocprov})
                time.sleep(1)
        print(listsocios)
        context={
        'sociosprov': listsocios,          
        }
        return context


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5e66006b-e173-4050-b192-9b5950ed9ad3n%40googlegroups.com.

Reply via email to