admin.py 1.42 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')
Thom Wiggers's avatar
Thom Wiggers committed
20

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

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


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

34
    fields = ('name', 'photo', 'permissions',
35
              'since', 'until',)
36

Thom Wiggers's avatar
Thom Wiggers committed
37
38

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


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