Commit afe6e999 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Merge branch 'fix/faster-activemembers-admin' into 'master'

Optimize the activemembers admin

See merge request !609
parents 9657cf64 9064d997
from django.contrib import admin
from django.contrib.auth.models import Permission
from django.forms import BaseInlineFormSet, ModelForm
from activemembers.forms import CommitteeMembershipForm
from utils.translation import TranslatedModelAdmin
from . import models
class CommitteeMembershipInlineFormSet(BaseInlineFormSet):
Solely here for performance reasons.
Needed because the `__str__()` of `CommitteeMembership` (which is displayed
above each inline form) uses the username, name of the member and name of
the committee.
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.queryset = self.queryset.select_related('member', 'committee')
class CommitteeMembershipInline(admin.StackedInline):
model = models.CommitteeMembership
formset = CommitteeMembershipInlineFormSet
can_delete = False
ordering = ('since',)
extra = 0
# TODO: replace this with `autocomplete_fields` in Django 2.0
raw_id_fields = ('member',)
class CommitteeForm(ModelForm):
Solely here for performance reasons.
Needed because the `__str__()` of `Permission` (which is displayed in the
permissions selection box) also prints the corresponding app and
`content_type` for each permission.
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['permissions'].queryset = (Permission
class CommitteeAdmin(TranslatedModelAdmin):
inlines = (CommitteeMembershipInline,)
form = CommitteeForm
list_display = ('name', 'since', 'until', 'active', 'email')
list_filter = ('until', 'active',)
search_fields = ('name', 'description')
......@@ -39,6 +75,7 @@ class CommitteeAdmin(TranslatedModelAdmin):
class BoardAdmin(TranslatedModelAdmin):
inlines = (CommitteeMembershipInline,)
form = CommitteeForm
exclude = ('is_board',)
filter_horizontal = ('permissions',)
......@@ -51,10 +88,11 @@ class CommitteeMembershipAdmin(TranslatedModelAdmin):
form = CommitteeMembershipForm
list_display = ('member', 'committee', 'since', 'until', 'chair', 'role')
list_filter = ('committee',)
list_select_related = ('member', 'committee',)
search_fields = ('member__first_name', 'member__last_name',
class MentorsAdmin(admin.ModelAdmin):
class MentorshipAdmin(admin.ModelAdmin):
list_select_related = ('member',)
Supports Markdown
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