admin.py 1.5 KB
Newer Older
Thom Wiggers's avatar
Thom Wiggers committed
1
from django.contrib import admin
2

3
from activemembers.forms import CommitteeMembershipForm
4
from utils.translation import TranslatedModelAdmin
Thom Wiggers's avatar
Thom Wiggers committed
5
6
from . import models

7

8
9
10
11
12
13
14
class CommitteeMembershipInline(admin.StackedInline):
    model = models.CommitteeMembership
    can_delete = False
    ordering = ('since',)
    extra = 0


Thom Wiggers's avatar
Thom Wiggers committed
15
@admin.register(models.Committee)
16
class CommitteeAdmin(TranslatedModelAdmin):
17
    inlines = (CommitteeMembershipInline,)
Thom Wiggers's avatar
Thom Wiggers committed
18
    list_filter = ('until',)
Joren Vrancken's avatar
Joren Vrancken committed
19
    search_fields = ('name', 'description')
20
    filter_horizontal = ('permissions',)
Thom Wiggers's avatar
Thom Wiggers committed
21

22
    fields = ('name', 'description', 'photo', 'permissions',
Thom Wiggers's avatar
Thom Wiggers committed
23
              'since', 'until', 'contact_email', 'wiki_namespace', 'active')
24

Thom Wiggers's avatar
Thom Wiggers committed
25
26
27
28
29
30
    def get_queryset(self, request):
        qs = super().get_queryset(request)
        return qs.exclude(board__is_board=True)


@admin.register(models.Board)
31
class BoardAdmin(TranslatedModelAdmin):
32
    inlines = (CommitteeMembershipInline,)
Thom Wiggers's avatar
Thom Wiggers committed
33
    exclude = ('is_board',)
34
    filter_horizontal = ('permissions',)
Thom Wiggers's avatar
Thom Wiggers committed
35

36
    fields = ('name', 'photo', 'permissions',
37
              'since', 'until',)
38

Thom Wiggers's avatar
Thom Wiggers committed
39
40

@admin.register(models.CommitteeMembership)
41
class CommitteeMembershipAdmin(TranslatedModelAdmin):
42
    form = CommitteeMembershipForm
43
    list_display = ('member', 'committee', 'since', 'until', 'chair', 'role')
44
45
46
    list_filter = ('committee',)
    search_fields = ('member__user__first_name', 'member__user__last_name',
                     'member__user__email')
47
48
49
50
51


@admin.register(models.Mentorship)
class MentorsAdmin(admin.ModelAdmin):
    pass