Add grade information to user search results and enhance user addition functionality
This commit is contained in:
+19
-4
@@ -6017,10 +6017,25 @@ def user_search_widget(request):
|
||||
limit = 50 if q in ("*", "%") or q_raw in ("*", "%") else 10
|
||||
users_qs = users_qs.order_by("last_name", "first_name")[:limit]
|
||||
|
||||
results = [
|
||||
{"id": u.pk, "text": f"{u.get_full_name() or u.username} - {u.email or ''}"}
|
||||
for u in users_qs
|
||||
]
|
||||
results = []
|
||||
for u in users_qs:
|
||||
grade = ""
|
||||
try:
|
||||
up = getattr(u, "userprofile", None)
|
||||
if up and getattr(up, "grade", None):
|
||||
# grade may be a FK object or a simple string depending on model
|
||||
g = up.grade
|
||||
grade = getattr(g, "name", str(g)) if g is not None else ""
|
||||
except Exception:
|
||||
grade = ""
|
||||
|
||||
results.append(
|
||||
{
|
||||
"id": u.pk,
|
||||
"text": f"{u.get_full_name() or u.username} - {u.email or ''}",
|
||||
"grade": grade,
|
||||
}
|
||||
)
|
||||
|
||||
return render(
|
||||
request,
|
||||
|
||||
Reference in New Issue
Block a user