создал таблицу с плейлистами
This commit is contained in:
parent
61cea1aaa4
commit
73e47e3cbc
|
|
@ -1,5 +1,5 @@
|
|||
from django.contrib import admin
|
||||
from .models import Song, FavoriteSong
|
||||
from .models import Song, FavoriteSong, PlayList
|
||||
|
||||
@admin.register(Song)
|
||||
class SongAdmin(admin.ModelAdmin):
|
||||
|
|
@ -9,3 +9,7 @@ class SongAdmin(admin.ModelAdmin):
|
|||
@admin.register(FavoriteSong)
|
||||
class FavoriteSongAdmin(admin.ModelAdmin):
|
||||
list_display = ('id', 'song', 'user')
|
||||
|
||||
@admin.register(PlayList)
|
||||
class PlayListAdmin(admin.ModelAdmin):
|
||||
list_display = ('id', 'name', 'user',)
|
||||
|
|
|
|||
|
|
@ -36,3 +36,9 @@ class FavoriteSong(models.Model):
|
|||
verbose_name = 'Избранные Треки'
|
||||
unique_together = ('song', 'user')
|
||||
verbose_name_plural = 'Избранные Треки'
|
||||
|
||||
|
||||
class PlayList(models.Model):
|
||||
name = models.CharField('Название плейлиста', max_length=50)
|
||||
song = models.ManyToManyField(Song)
|
||||
user = models.ForeignKey(MyUser, verbose_name='Пользователь', on_delete=models.CASCADE, blank=True, null=True)
|
||||
|
|
@ -1,11 +1,24 @@
|
|||
from rest_framework import serializers
|
||||
from .models import Song, FavoriteSong
|
||||
from .models import Song, FavoriteSong, PlayList
|
||||
|
||||
class SongSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Song
|
||||
fields = ('id', 'unique_id', 'azura_id', 'title', 'artist', 'album', 'genre', 'art')
|
||||
|
||||
class PlayListSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = PlayList
|
||||
fields = ('id', 'name', 'song')
|
||||
|
||||
def to_representation(self, instance):
|
||||
rep = super().to_representation(instance)
|
||||
rep["song"] = SongSerializer(
|
||||
instance.song.all(), many=True).data
|
||||
return rep
|
||||
|
||||
|
||||
|
||||
class FavoriteSongSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
|
|
|
|||
|
|
@ -10,8 +10,28 @@ import requests
|
|||
from django.http import HttpResponse
|
||||
|
||||
from .schemas import SongSchema, DeleteSongSchema
|
||||
from .models import Song, FavoriteSong
|
||||
from .serializers import SongSerializer, FavoriteSongSerializer
|
||||
from .models import Song, FavoriteSong, PlayList
|
||||
from .serializers import SongSerializer, FavoriteSongSerializer, PlayListSerializer
|
||||
|
||||
class PlayListViewSet(GenericViewSet):
|
||||
queryset = PlayList
|
||||
serializer_class = PlayListSerializer
|
||||
permission_classes = (IsAuthenticated,)
|
||||
def list(self, request):
|
||||
queryset = self.get_queryset().objects.filter(user=request.user)
|
||||
serializer = self.get_serializer(queryset, many=True)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
|
||||
def retrieve(self, request, pk):
|
||||
try:
|
||||
queryset = self.get_queryset().objects.get(pk=pk, user=request.user)
|
||||
serializer = self.get_serializer(queryset)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
except ObjectDoesNotExist:
|
||||
return Response({"error": 'Объекта не существует'}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
|
||||
|
||||
|
||||
class SongViewSet(GenericViewSet):
|
||||
queryset = Song.objects.all()
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -12,12 +12,13 @@ from userProfile.views import TeamViewSet
|
|||
from django.conf import settings
|
||||
from rubricks.views import RubricViewSet
|
||||
from api.views import FetchAndServeFile
|
||||
from audio.views import SongViewSet
|
||||
from audio.views import SongViewSet, PlayListViewSet
|
||||
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'teams', TeamViewSet, basename='teams')
|
||||
router.register(r'rubriks', RubricViewSet, basename='rubriks')
|
||||
router.register(r'playlists', PlayListViewSet, basename='playlists')
|
||||
router.register(r'song', SongViewSet, basename='song')
|
||||
router.register(r'fetchandservefile', FetchAndServeFile, basename='fetchandservefile')
|
||||
|
||||
|
|
|
|||
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.
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.
Loading…
Reference in New Issue