|
6 | 6 | from typing import Any |
7 | 7 |
|
8 | 8 | from django.core.exceptions import ObjectDoesNotExist |
9 | | -from django.db.models import Avg, CharField, F, Q, Value |
| 9 | +from django.db.models import Avg, CharField, Count, F, Q, Value |
10 | 10 | from django.db.models.functions import Concat |
11 | 11 | from django.http import Http404 |
12 | 12 | from django.shortcuts import get_object_or_404, redirect, render |
@@ -194,8 +194,11 @@ def course_instructor(request, course_id, instructor_id, method="Most Recent"): |
194 | 194 | course = section_last_taught.course |
195 | 195 | instructor = section_last_taught.instructors.get(pk=instructor_id) |
196 | 196 |
|
197 | | - # Find the total number of reviews (with or without text) for the given course |
198 | | - num_reviews = Review.objects.filter(instructor=instructor_id, course=course_id).count() |
| 197 | + # ratings: reviews with and without text; reviews: ratings with text |
| 198 | + reviews = Review.objects.filter(instructor=instructor_id, course=course_id).aggregate( |
| 199 | + num_ratings=Count("id"), num_reviews=Count("id", filter=~Q(text="")) |
| 200 | + ) |
| 201 | + num_reviews, num_ratings = reviews["num_reviews"], reviews["num_ratings"] |
199 | 202 |
|
200 | 203 | dept = course.subdepartment.department |
201 | 204 |
|
@@ -295,6 +298,7 @@ def course_instructor(request, course_id, instructor_id, method="Most Recent"): |
295 | 298 | "course_id": course_id, |
296 | 299 | "instructor": instructor, |
297 | 300 | "semester_last_taught": section_last_taught.semester, |
| 301 | + "num_ratings": num_ratings, |
298 | 302 | "num_reviews": num_reviews, |
299 | 303 | "paginated_reviews": paginated_reviews, |
300 | 304 | "breadcrumbs": breadcrumbs, |
|
0 commit comments