Commit 3075ad49 authored by Ilya Simonov's avatar Ilya Simonov

add retrieve endpoint for playlyst by id

parent 0f8b071a
from rest_framework import serializers
from .models import Video, Category, Tag, TagToObject
from .models import Video, Playlist, Category, TagToObject
class TagToObjectSerializer(serializers.ModelSerializer):
......@@ -34,3 +34,22 @@ class VideoSerializer(serializers.ModelSerializer):
'categories',
'tags',
]
class PlaylistSerializer(serializers.ModelSerializer):
videos = VideoSerializer(many=True)
tags = TagToObjectSerializer(many=True)
class Meta:
model = Playlist
fields = [
'id',
'title',
'description',
'sort',
'type',
'mrss',
'json',
'videos',
'tags',
]
......@@ -6,7 +6,8 @@ from . import models
@receiver(post_save, sender=models.Playlist)
def save_playlist_mrss(sender, instance, created, **kwargs):
def save_playlist_links(sender, instance, created, **kwargs):
if created:
instance.json = f'{settings.DOMAIN_NAME}/api/playlist/{instance.id}/'
instance.mrss = f'{settings.DOMAIN_NAME}/api/playlist/{instance.id}/mrss'
instance.save()
......@@ -5,5 +5,6 @@ from . import views
urlpatterns = [
path('video/', views.VideoAPIView.as_view({'get': 'list'})),
path('playlist/<int:pk>/', views.VideoRetrieveAPIView.as_view()),
path('playlist/<int:pk>/mrss', views.playlist_mrss_view),
]
from rest_framework import permissions, viewsets
from rest_framework import permissions, viewsets, generics
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
......@@ -22,6 +22,13 @@ class VideoAPIView(viewsets.ModelViewSet):
return queryset
class VideoRetrieveAPIView(generics.RetrieveAPIView):
queryset = models.Playlist.objects.all()
serializer_class = serializers.PlaylistSerializer
permission_classes = [permissions.AllowAny]
lookup_field = 'pk'
def playlist_mrss_view(request, pk):
mrss_items = []
playlist = get_object_or_404(models.Playlist, pk=pk)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment