Skip to content

Commit 545ff4b

Browse files
authored
Add taxon group expert info to user admin page (#5024)
1 parent f793974 commit 545ff4b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

bims/admin.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,15 @@ class ProfileInline(admin.StackedInline):
711711
model = BimsProfile
712712

713713

714+
class TaxonGroupExpertInline(admin.TabularInline):
715+
"""Inline to assign user as expert for taxon groups."""
716+
model = TaxonGroup.experts.through
717+
extra = 1
718+
verbose_name = 'Expert for Taxon Group'
719+
verbose_name_plural = 'Expert for Taxon Groups'
720+
autocomplete_fields = ['taxongroup']
721+
722+
714723
class BimsProfileAdmin(admin.ModelAdmin):
715724
model = BimsProfile
716725
list_display = [
@@ -841,7 +850,7 @@ def queryset(self, request, queryset):
841850
class CustomUserAdmin(ProfileAdmin):
842851
add_form = UserCreateForm
843852
change_form_template = 'admin/user_changeform.html'
844-
inlines = [ProfileInline]
853+
inlines = [ProfileInline, TaxonGroupExpertInline]
845854
add_fieldsets = (
846855
(None, {
847856
'classes': ('wide',),
@@ -861,6 +870,7 @@ class CustomUserAdmin(ProfileAdmin):
861870
'is_active',
862871
'signed_up',
863872
'sass_accredited_status',
873+
'expert_taxon_groups',
864874
'date_joined',
865875
'last_login'
866876
)
@@ -1017,6 +1027,15 @@ def signed_up(self, obj, **kwargs):
10171027
pass
10181028
return true_response
10191029

1030+
def expert_taxon_groups(self, obj):
1031+
"""Return the taxon groups where this user is an expert."""
1032+
taxon_groups = TaxonGroup.objects.filter(experts=obj)
1033+
if not taxon_groups.exists():
1034+
return '-'
1035+
return ', '.join([str(tg.name) for tg in taxon_groups])
1036+
1037+
expert_taxon_groups.short_description = 'Expert for Taxon Groups'
1038+
10201039
def save_model(self, request, obj, form, change):
10211040
if obj.pk is None:
10221041
obj.is_active = False

0 commit comments

Comments
 (0)