admin.py 908 Bytes
Newer Older
1
from django.contrib import admin
2
from django.utils.translation import ugettext_lazy as _
3

4
from .models import ListAlias, MailingList, VerbatimAddress
5
6
7


class VerbatimAddressInline(admin.TabularInline):
Joren Vrancken's avatar
Joren Vrancken committed
8
9
    """Class to inline show the VerbatimAddress."""

10
11
12
13
    model = VerbatimAddress


class ListAliasInline(admin.TabularInline):
Joren Vrancken's avatar
Joren Vrancken committed
14
15
    """Class to inline show the ListAlias."""

16
17
18
19
    model = ListAlias


@admin.register(MailingList)
20
class MailingListAdmin(admin.ModelAdmin):
Joren Vrancken's avatar
Joren Vrancken committed
21
22
    """Class to show the mailing lists in the admin."""

23
    filter_horizontal = ('members',)
24
    inlines = (VerbatimAddressInline, ListAliasInline)
25
26
27
28
    list_display = ('name', 'alias_names',)
    search_fields = ['name', 'prefix', 'aliasses__alias']

    def alias_names(self, obj):
Joren Vrancken's avatar
Joren Vrancken committed
29
        """Return list of aliases of obj."""
30
31
        return [x.alias for x in obj.aliasses.all()]
    alias_names.short_description = _('List aliasses')