Skip to content

Updating the lead count for each category #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions leads/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 12 additions & 2 deletions leads/templates/leads/category_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,24 @@ <h1 class="sm:text-4xl text-3xl font-medium title-font mb-2 text-gray-900">Categ
<td class="px-4 py-3">Unassigned</td>
<td class="px-4 py-3">{{ unassigned_lead_count }}</td>
</tr>
{% for category in category_list %}
<!-- {% for category in category_list %}
<tr>
<td class="px-4 py-3">
<a class="hover:text-blue-500" href="{% url 'leads:category-detail' category.pk %}">{{ category.name }}</a>
</td>
<td class="px-4 py-3">TODO count</td>
</tr>
{% endfor %}
{% endfor %} -->

{% for ret in reset %}
<div>
<tr>
<td class="px-4 py-3" > <a href="{% url 'leads:category-detail' ret.id %}">{{ ret.name }} </a></td>
<td class="px-4 py-3">{{ ret.number }}</td>
</tr>
</div>
{% endfor %}

</tbody>
</table>
</div>
Expand Down
23 changes: 20 additions & 3 deletions leads/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,23 +262,40 @@ 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
# <QuerySet [{'id': 6, 'name': 'developer', 'organisation_id': 1},
# {'id': 7, 'name': 'salary', 'organisation_id': 1},
# {'id': 8, 'name': 'DevOps', 'organisation_id': 1}]>
cate_list = context['object_list'].values()
list_of_categories = []

if user.is_organisor:
queryset = Lead.objects.filter(
organisation=user.userprofile
)
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
Expand Down