Hello everyone!
By following program, blanks are also counted.
Where should I change to count without blanks?
admin.py
from .models import Inquiry
from django.db.models import Count
from django.contrib import admin
class InquiryAdmin(admin.ModelAdmin):
change_list_template = ‘admin/Inquiry_change_list.html’
date_hierarchy = ‘reception_datetime’
def changelist_view(self, request, extra_context=None):
response = super().changelist_view(request, extra_context=extra_context, )
try:
qs = response.context_data['cl'].queryset
except (AttributeError, KeyError):
return response
metrics = { 'total': Count('customer') }
response.context_data['summary6'] = list( qs.values('customer'). annotate(**metrics) )
response.context_data['summary6_total'] = dict( qs.aggregate(**metrics) )
return response
admin.site.register(Inquiry, InquiryAdmin)
Inquiry_change_list.html
{% extends “admin/change_list.html” %}
{% block result_list %}
{{ row.customer }} | {{ row.total }} cases |
Total Cases | {{ summary6_total.total | default:0 }} cases |
model.py
from django.db import models
from django.utils import timezone
class Inquiry(models.Model):
customer = models.CharField(verbose_name='Serial No', max_length=100, blank=True,
def __str__(self):
return self.subject