Reputation: 565
I am developing an application that sends data and represents it in a graph, the problem is that when I print the data it does it the way I want it, but when returning the data it only sends the first one, not the rest.
This is my view.
class DeveloperDatailView(DetailView):
template_name = 'dates/dates.html'
model = Developer
def activities_porcentage(self):
projects = Project.objects.filter(developer=self.kwargs['pk'])
for project in projects:
tasks = Task.objects.filter(project=project).filter(state=True)
for task in tasks:
activities = Activities.objects.filter(task=task).count()
complete = Activities.objects.filter(task=task).filter(process=False).count()
data = int((complete * 100) / activities)
return data
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['projects'] = Project.objects.filter(
developer=self.kwargs['pk'])
context['quantity'] = Project.objects.filter(
developer=self.kwargs['pk']).count()
context['activities'] = self.activities_porcentage()
return context
Upvotes: 0
Views: 30
Reputation: 536
From what I can see, it seems like you need to add the data you are processing to a list and then return the list at the end of your for loop e.g
def activities_porcentage(self):
projects = Project.objects.filter(developer=self.kwargs['pk'])
data = []
for project in projects:
tasks = Task.objects.filter(project=project).filter(state=True)
for task in tasks:
activities = Activities.objects.filter(task=task).count()
complete = Activities.objects.filter(task=task).filter(process=False).count()
data.append(int((complete * 100) / activities))
return data
At the moment you have a return statement returning data
after the first iteration.
Upvotes: 1