Skip to content

Commit

Permalink
Make GSR Group Admin easy to add/remove users (#307)
Browse files Browse the repository at this point in the history
* Make GSR Group Admin easy to add/remove users

* linting
  • Loading branch information
vcai122 authored Sep 30, 2024
1 parent 4f18580 commit ef44d80
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion backend/gsr_booking/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@
from gsr_booking.models import GSR, Group, GroupMembership, GSRBooking, Reservation


class GroupMembershipInline(admin.TabularInline):
model = GroupMembership
extra = 0

readonly_fields = ["name"]

def name(self, obj):
return obj.user.get_full_name()

def get_fields(self, request, obj=None):
fields = super().get_fields(request, obj)
to_remove = ["user", "name"]
return ["name"] + [f for f in fields if f not in to_remove]


class GroupAdmin(admin.ModelAdmin):
search_fields = ["name__icontains"]
list_display = ["name"]
ordering = ["name"]

inlines = [GroupMembershipInline]


class GroupMembershipAdmin(admin.ModelAdmin):
search_fields = ["user__username__icontains", "group__name__icontains"]

Expand All @@ -16,7 +39,7 @@ def get_queryset(self, request):
ordering = ["-in_use"]


admin.site.register(Group)
admin.site.register(Group, GroupAdmin)
admin.site.register(GroupMembership, GroupMembershipAdmin)
admin.site.register(GSR, GSRAdmin)
admin.site.register(GSRBooking)
Expand Down

0 comments on commit ef44d80

Please sign in to comment.