Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Adrián Ribao
Cartero
Commits
d70b702a
Commit
d70b702a
authored
Oct 10, 2016
by
Adrián Ribao
Browse files
show the number of contacts for each list
parent
e8ff378d
Pipeline
#358
passed with stage
in 56 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
cartero/admin.py
View file @
d70b702a
# -*- 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
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment