diff --git a/leads/models.py b/leads/models.py
index b39843c..4c93c80 100644
--- a/leads/models.py
+++ b/leads/models.py
@@ -64,6 +64,7 @@ def __str__(self):
class Category(models.Model):
name = models.CharField(max_length=30) # New, Contacted, Converted, Unconverted
+ number = models.IntegerField(default=0)
organisation = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
def __str__(self):
diff --git a/leads/templates/leads/category_list.html b/leads/templates/leads/category_list.html
index 3f9c779..a1603aa 100644
--- a/leads/templates/leads/category_list.html
+++ b/leads/templates/leads/category_list.html
@@ -24,14 +24,24 @@
Categ
Unassigned |
{{ unassigned_lead_count }} |
- {% for category in category_list %}
+
+
+ {% for ret in reset %}
+
+ {% endfor %}
+
diff --git a/leads/views.py b/leads/views.py
index 8d2f89b..64d1197 100644
--- a/leads/views.py
+++ b/leads/views.py
@@ -262,8 +262,14 @@ class CategoryListView(LoginRequiredMixin, generic.ListView):
context_object_name = "category_list"
def get_context_data(self, **kwargs):
- context = super(CategoryListView, self).get_context_data(**kwargs)
user = self.request.user
+ context = super(CategoryListView, self).get_context_data(**kwargs)
+ # Extraction of the Categories info
+ #
+ cate_list = context['object_list'].values()
+ list_of_categories = []
if user.is_organisor:
queryset = Lead.objects.filter(
@@ -271,14 +277,25 @@ def get_context_data(self, **kwargs):
)
else:
queryset = Lead.objects.filter(
- organisation=user.agent.organisation
+ organisations=user.agent.organisation
)
+ # Looping over the extracted list of dictionaries
+ for cate_number in cate_list:
+ # Update The number field in each category by counting all the leads that connected to this category
+ cate_number['number'] = queryset.filter(
+ category=cate_number['id']).count()
+ x = {'id': cate_number['id'], 'name': cate_number['name'],
+ 'number': cate_number['number']}
+ list_of_categories.append(x)
context.update({
- "unassigned_lead_count": queryset.filter(category__isnull=True).count()
+ "unassigned_lead_count": queryset.filter(category__isnull=True).count(),
+ "reset": list_of_categories
+
})
return context
+
def get_queryset(self):
user = self.request.user
# initial queryset of leads for the entire organisation