diff --git a/src/teams/admin.py b/src/teams/admin.py index cf306dc1..3ffe9b35 100644 --- a/src/teams/admin.py +++ b/src/teams/admin.py @@ -4,6 +4,7 @@ from .models import Team, TeamArea, TeamMember admin.site.register(TeamArea) + @admin.register(Team) class TeamAdmin(admin.ModelAdmin): def get_responsible(self, obj): @@ -22,6 +23,7 @@ class TeamAdmin(admin.ModelAdmin): 'needs_members', ] + @admin.register(TeamMember) class TeamMemberAdmin(admin.ModelAdmin): list_filter = [ @@ -29,4 +31,28 @@ class TeamMemberAdmin(admin.ModelAdmin): 'approved', ] + actions = ['add_member', 'remove_member'] + def add_member(self, request, queryset): + teams_count = queryset.values('team').distinct().count() + rows_updated = queryset.update(approved=True) + self.message_user( + request, + 'Added {} user(s) to {} team(s).'.format( + rows_updated, + teams_count + ) + ) + add_member.description = 'Add a user to the team.' + + def remove_member(self, request, queryset): + teams_count = queryset.values('team').distinct().count() + users_removed = queryset.delete()[0] + self.message_user( + request, + 'Removed {} user(s) from {} team(s).'.format( + users_removed, + teams_count + ) + ) + remove_member.description = 'Remove a user from the team.'