# Django How to Count in Admin-site without blank

**URL:** <https://forum.djangoproject.com/t/django-how-to-count-in-admin-site-without-blank/14674>\
**Category:** Using the ORM\
**Created:** [July 7, 2022, 12:58pm UTC](https://forum.djangoproject.com/t/django-how-to-count-in-admin-site-without-blank/14674 "2022-07-07T12:58:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tkt1112](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tkt1112/32/9177_2.png) [@tkt1112](https://forum.djangoproject.com/u/tkt1112)\
**Post date:** [July 7, 2022, 12:58pm UTC](https://forum.djangoproject.com/t/django-how-to-count-in-admin-site-without-blank/14674/1 "2022-07-07T12:58:11Z")

</div>

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 %}

 {% for row in summary6 %} {% endfor %} 

|
| |
| {{ row.customer }} | {{ row.total }} cases |
| Total Cases | {{ summary6\_total.total | default:0 }} cases |

{% endblock %}

**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

```

 ![Inquiry_change_list](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/2/21071f4a45abf13fb85cb10f148d74d345313db0.jpeg)

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 7, 2022, 2:33pm UTC](https://forum.djangoproject.com/t/django-how-to-count-in-admin-site-without-blank/14674/2 "2022-07-07T14:33:22Z")

</div>

What is it that you want counted without blanks?

You show what you’re currently getting, but I’m not understanding what it is that you _want_ to see here.

---

<div class="post-metadata">

**Author:** ![tkt1112](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tkt1112/32/9177_2.png) [@tkt1112](https://forum.djangoproject.com/u/tkt1112)\
**Post date:** [July 8, 2022, 12:55am UTC](https://forum.djangoproject.com/t/django-how-to-count-in-admin-site-without-blank/14674/3 "2022-07-08T00:55:47Z")

</div>

Hi

even if nothing is entered in charfield, it is still counted.  
so I want to count only the fields where characters are entered.

---

<div class="post-metadata">

**Author:** ![tkt1112](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tkt1112/32/9177_2.png) [@tkt1112](https://forum.djangoproject.com/u/tkt1112)\
**Post date:** [July 10, 2022, 1:11pm UTC](https://forum.djangoproject.com/t/django-how-to-count-in-admin-site-without-blank/14674/4 "2022-07-10T13:11:25Z")

</div>

![Inquiry_change_list](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/d/d2ee6f28957261575a6ccfb281f4158a2f96ff9a.jpeg)

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 10, 2022, 1:18pm UTC](https://forum.djangoproject.com/t/django-how-to-count-in-admin-site-without-blank/14674/5 "2022-07-10T13:18:10Z")

</div>

You should be able to [`exclude`](https://docs.djangoproject.com/en/4.0/ref/models/querysets/#exclude) the rows from your queryset where the `customer` field is blank.

So after your `try `/` except` block and before the `metrics = ` line you could try something like:

`qs = qs.exclude(customer='')`
