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 87edc6a commit f5b07ad
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions S1/waitinglists/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@
class SessionAdmin(admin.ModelAdmin):
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).order_by(
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()
kwargs["queryset"] = (
User.objects.none()
) # No group found, no users displayed
return super().formfield_for_foreignkey(db_field, request, **kwargs)

def label_from_instance(self, obj):
return f"{obj.first_name} {obj.last_name}"
# 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)
Expand Down

0 comments on commit f5b07ad

Please sign in to comment.