Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make GSR Group Admin easy to add/remove users #307

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()

Check warning on line 13 in backend/gsr_booking/admin.py

View check run for this annotation

Codecov / codecov/patch

backend/gsr_booking/admin.py#L13

Added line #L13 was not covered by tests
dr-Jess marked this conversation as resolved.
Show resolved Hide resolved

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]

Check warning on line 18 in backend/gsr_booking/admin.py

View check run for this annotation

Codecov / codecov/patch

backend/gsr_booking/admin.py#L16-L18

Added lines #L16 - L18 were not covered by tests


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 @@
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
Loading