add admin actions to add/remove users from teams
This commit is contained in:
parent
7b2659df4a
commit
6bc0d57a52
|
@ -4,6 +4,7 @@ from .models import Team, TeamArea, TeamMember
|
||||||
|
|
||||||
admin.site.register(TeamArea)
|
admin.site.register(TeamArea)
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Team)
|
@admin.register(Team)
|
||||||
class TeamAdmin(admin.ModelAdmin):
|
class TeamAdmin(admin.ModelAdmin):
|
||||||
def get_responsible(self, obj):
|
def get_responsible(self, obj):
|
||||||
|
@ -22,6 +23,7 @@ class TeamAdmin(admin.ModelAdmin):
|
||||||
'needs_members',
|
'needs_members',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@admin.register(TeamMember)
|
@admin.register(TeamMember)
|
||||||
class TeamMemberAdmin(admin.ModelAdmin):
|
class TeamMemberAdmin(admin.ModelAdmin):
|
||||||
list_filter = [
|
list_filter = [
|
||||||
|
@ -29,4 +31,28 @@ class TeamMemberAdmin(admin.ModelAdmin):
|
||||||
'approved',
|
'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.'
|
||||||
|
|
Loading…
Reference in a new issue