def get_queryset(self):
"""
Returns a queryset used for autocompletion, restricted based
on the user input.
"""
# Only let logged in users access all the course information
if not self.request.user.is_authenticated():
return Course.objects.none()
qs = Course.objects.all()
# If the user has started entering input, start restricting
# the choices available for autocompletion.
if self.q:
course_code = Q(course_code__istartswith=self.q)
full_name = Q(full_name__istartswith=self.q)
display_name = Q(display_name__startswith=self.q)
qs = qs.filter(course_code | full_name | display_name)
return qs
评论列表
文章目录