Skip to content

Commit

Permalink
Admin interface
Browse files Browse the repository at this point in the history
  • Loading branch information
fsoest committed Jan 1, 2025
1 parent f5b07ad commit a4aa82b
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions S1/waitinglists/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,20 @@


class SessionAdmin(admin.ModelAdmin):
# Other configurations like list_display, search_fields, etc.

def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "mentor":
# Filter users who belong to the "Mentor" group
mentor_group = Group.objects.filter(name="Mentor").first()
if mentor_group:
kwargs["queryset"] = User.objects.filter(groups=mentor_group)
# Customize the display label in the dropdown
kwargs["queryset"] = kwargs["queryset"].order_by(
"first_name", "last_name"
)
else:
kwargs["queryset"] = (
User.objects.none()
) # No group found, no users displayed
return super().formfield_for_foreignkey(db_field, request, **kwargs)

# Optional: Customize how users are displayed in the dropdown
def get_queryset(self, request):
qs = super().get_queryset(request)
qs = qs.annotate(full_name=Concat("first_name", Value(" "), "last_name"))
return qs


admin.site.register(Attendance)
admin.site.register(Module)
Expand Down

0 comments on commit a4aa82b

Please sign in to comment.