Api endpoint for video search with querying implemented
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -2,4 +2,5 @@ db.sqlite3
|
||||
videos/
|
||||
channel_archiver/yt-dlp-archive.txt
|
||||
channel_archiver/UnusualVideos*
|
||||
*__pycache__*
|
||||
*__pycache__*
|
||||
*.pyc
|
||||
@@ -2,5 +2,5 @@ from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.query)
|
||||
path('', views.videoAPI),
|
||||
]
|
||||
@@ -2,9 +2,11 @@ from rest_framework.response import Response
|
||||
from rest_framework.decorators import api_view
|
||||
from core.models import Video
|
||||
from core.serializers import VideoSerializer
|
||||
from django.db.models import Q
|
||||
|
||||
@api_view(['GET'])
|
||||
def query(request):
|
||||
videos = Video.objects.all()
|
||||
def videoAPI(request):
|
||||
q = request.GET.get('q', '')
|
||||
videos = Video.objects.filter(Q(id__contains=q) | Q(name__contains=q))
|
||||
serializer = VideoSerializer(videos, many=True)
|
||||
return Response(serializer.data)
|
||||
return Response(serializer.data)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user