diff --git a/api/urls.py b/api/urls.py index ad6ea78..78120eb 100644 --- a/api/urls.py +++ b/api/urls.py @@ -2,6 +2,6 @@ from django.urls import path, include from . import views urlpatterns = [ - path('search/', views.searchAPI), path('', include('sage_stream.api.urls')), + path('search/', views.searchAPI), ] \ No newline at end of file diff --git a/core/templates/base.html b/core/templates/base.html index 5ad9c4d..d9df30b 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -56,14 +56,15 @@
-
+
+ id="search" + name="q"> diff --git a/core/urls.py b/core/urls.py index 6cec69f..e56b7be 100644 --- a/core/urls.py +++ b/core/urls.py @@ -3,8 +3,9 @@ from . import views urlpatterns = [ path('', views.core, name='core'), - path('status/', views.status, name='status'), path('about/', views.about, name='about'), path('random/', views.random, name='random'), + path('search/', views.search, name='search'), + path('status/', views.status, name='status'), path('view/', views.view, name='view'), ] diff --git a/core/views.py b/core/views.py index 3800c1e..299e0b5 100644 --- a/core/views.py +++ b/core/views.py @@ -1,3 +1,4 @@ +from django.db.models import Q from django.shortcuts import render from django.shortcuts import redirect from core.models import Video @@ -8,16 +9,24 @@ def core(request): videos = Video.objects.all() return render(request, 'base.html', {'videos': videos[::-1]}) +def about(request): + return render(request, 'about.html') + def random(request): videos = Video.objects.all().order_by("?") ran = videos.first() return redirect('/view/'+str(ran.id)) +def search(request): + q = request.GET.get('q', '') + videos = Video.objects.filter(Q(id__contains=q) | Q(name__contains=q)) + return render(request, 'base.html', {'videos': videos}) + def status(request): highest_id = Video.objects.order_by('-id').first().id video_list = [] - for i in range(highest_id + 1): + for i in range(1, highest_id + 1): try: video = Video.objects.get(id=i) video_list.append(video) @@ -30,6 +39,3 @@ def view(request, id): vid = Video.objects.get(id = id) if vid: return render(request, "view.html", {'video': vid}) - -def about(request): - return render(request, 'about.html')