Commit d70b702a authored by Adrián Ribao's avatar Adrián Ribao
Browse files

show the number of contacts for each list

parent e8ff378d
Pipeline #358 passed with stage
in 56 seconds
# -*- coding: utf-8 -*-
from django.conf.urls import patterns
from django.contrib import admin
from django.db.models import Count
from django.utils.translation import ugettext_lazy as _
from .models import Contact, EmailTemplate, Campaign, ExcludedEmail,\
......@@ -48,11 +49,21 @@ admin.site.register(Contact, ContactAdmin)
class ContactListAdmin(admin.ModelAdmin):
list_display = [
'name',
'num_contacts',
]
search_fields = [
'name',
]
def get_queryset(self, request):
qs = super(ContactListAdmin, self).get_queryset(request)
qs = qs.annotate(num_contacts=Count('contacts'))
return qs
def num_contacts(self, obj):
return ("%s" % (obj.num_contacts, ))
num_contacts.short_description = '# Contacts'
@admin.register(ContactInList)
class ContactInListAdmin(admin.ModelAdmin):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment