diff --git a/backend/RateMyCourse/urls.py b/backend/RateMyCourse/urls.py index cc3e5cb..581fd0f 100644 --- a/backend/RateMyCourse/urls.py +++ b/backend/RateMyCourse/urls.py @@ -24,6 +24,9 @@ urlpatterns = [ # / routes to index.html path('', views.index, name='homepage'), + # /?search_query=xxx routes to the homepage, with displaying some basic results. + path(' - Click one of the links below to view a list of all those entities. -

- + + + + {# Second section for displaying results, or whatever should be shown first. #} + {% if results %} +
+ +
+ {% endif %} + {% endblock %} \ No newline at end of file diff --git a/backend/postings/views.py b/backend/postings/views.py index 58288a1..61c25b9 100644 --- a/backend/postings/views.py +++ b/backend/postings/views.py @@ -5,8 +5,14 @@ from postings.models import * # Create your views here. # The view for the homepage, or index.html +# There is an optional 'search_query GET parameter, which, if provided, gives the template a 'results' variable. def index(request): - return render(request, 'postings/index.html') + search_query = request.GET.get('search_query', None) + results = None + if search_query: + results = RateableEntity.objects.filter(name__icontains=search_query) + + return render(request, 'postings/index.html', {'results': results}) # The view for a listing of universities. def universities(request):