создал функционал для сохранения треков
This commit is contained in:
parent
e00dab5aa8
commit
53ea3f2aa9
|
|
@ -1,3 +1,6 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from .models import Song
|
||||||
|
|
||||||
# Register your models here.
|
@admin.register(Song)
|
||||||
|
class SongAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ('title', 'artist', 'genre', 'album')
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
# class Song(models.Model):
|
class Song(models.Model):
|
||||||
# name = models.CharField(max_length=255)
|
azura_id = models.CharField('ID трека с Азуры', max_length=255)
|
||||||
# artist = models.CharField(max_length=255)
|
title = models.CharField('Название трека', max_length=255)
|
||||||
# album = models.ForeignKey('Album', on_delete=models.CASCADE)
|
artist = models.CharField('Исполнитель', max_length=255)
|
||||||
# ...
|
album = models.CharField('Альбом трека', blank=True, null=True, max_length=255)
|
||||||
|
genre = models.CharField('Жанр трека', blank=True, null=True, max_length=50)
|
||||||
|
art = models.ImageField('Изображение трека', blank=True, null=True, upload_to="song_images/")
|
||||||
|
|
||||||
# class Playlist(models.Model):
|
def __str__(self, request):
|
||||||
# songs = models.ManyToManyField(Song)
|
return f"{self.artist} - {self.title}"
|
||||||
|
|
||||||
# class Podcast(models.Model):
|
|
||||||
# name = models.CharField(max_length=255)
|
|
||||||
# hosts = models.CharField(max_length=255)
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
from rest_framework.schemas import AutoSchema
|
||||||
|
import coreapi
|
||||||
|
import coreschema
|
||||||
|
|
||||||
|
class SongSchema(AutoSchema):
|
||||||
|
def get_serializer_fields(self, path, method):
|
||||||
|
return [
|
||||||
|
coreapi.Field(
|
||||||
|
name='azura_id',
|
||||||
|
location='form',
|
||||||
|
required=False,
|
||||||
|
schema=coreschema.String(description='ID трека с Азуры')
|
||||||
|
),
|
||||||
|
coreapi.Field(
|
||||||
|
name='title',
|
||||||
|
location='form',
|
||||||
|
required=False,
|
||||||
|
schema=coreschema.Array(description='Название трека')
|
||||||
|
),
|
||||||
|
coreapi.Field(
|
||||||
|
name='artist',
|
||||||
|
location='form',
|
||||||
|
required=False,
|
||||||
|
schema=coreschema.Integer(description='Исполнитель')
|
||||||
|
),
|
||||||
|
coreapi.Field(
|
||||||
|
name='album',
|
||||||
|
location='form',
|
||||||
|
required=False,
|
||||||
|
schema=coreschema.Integer(description='Альбом трека')
|
||||||
|
),
|
||||||
|
coreapi.Field(
|
||||||
|
name='genre',
|
||||||
|
location='form',
|
||||||
|
required=False,
|
||||||
|
schema=coreschema.Integer(description='Жанр трека')
|
||||||
|
),
|
||||||
|
coreapi.Field(
|
||||||
|
name='art',
|
||||||
|
location='form',
|
||||||
|
required=False,
|
||||||
|
schema=coreschema.Integer(description='Изображение трека')
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
from rest_framework import serializers
|
||||||
|
from .models import Song
|
||||||
|
|
||||||
|
class SongSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Song
|
||||||
|
fields = ('id', 'azura_id', 'title', 'artist', 'album', 'genre', 'art')
|
||||||
|
|
@ -1,3 +1,24 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
from rest_framework.viewsets import ViewSet
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from rest_framework.decorators import action
|
||||||
|
from rest_framework import status
|
||||||
|
|
||||||
# Create your views here.
|
from .schemas import SongSchema
|
||||||
|
from .models import Song
|
||||||
|
from .serializers import SongSerializer
|
||||||
|
|
||||||
|
class SongViewSet(ViewSet):
|
||||||
|
def list(self, request):
|
||||||
|
queryset = Song.objects.all()
|
||||||
|
serializer = SongSerializer(queryset, many=True)
|
||||||
|
return Response(serializer.data)
|
||||||
|
|
||||||
|
@action(detail=False, methods=['post'], schema=SongSchema())
|
||||||
|
def create_song(self, request):
|
||||||
|
song = SongSerializer(data=request.data)
|
||||||
|
if song.is_valid():
|
||||||
|
song.save()
|
||||||
|
return Response(song.data)
|
||||||
|
else:
|
||||||
|
return Response(status=status.HTTP_404_NOT_FOUND)
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from rest_framework.documentation import include_docs_urls
|
from rest_framework.documentation import include_docs_urls
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
# from api.views import AzuraNowPlayingWebhookView
|
|
||||||
#from loginApi.views import login, register
|
|
||||||
from rest_framework_simplejwt.views import (
|
from rest_framework_simplejwt.views import (
|
||||||
TokenObtainPairView,
|
TokenObtainPairView,
|
||||||
TokenRefreshView,
|
TokenRefreshView,
|
||||||
|
|
@ -10,20 +8,21 @@ from rest_framework_simplejwt.views import (
|
||||||
)
|
)
|
||||||
from django.conf.urls.static import static
|
from django.conf.urls.static import static
|
||||||
from news import views as newsViews
|
from news import views as newsViews
|
||||||
from rest_framework import routers, serializers, viewsets
|
from rest_framework import routers
|
||||||
#from userProfile.views import ProfileViewSet, TeamViewSet
|
|
||||||
from userProfile.views import TeamViewSet
|
from userProfile.views import TeamViewSet
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from rubricks.views import RubricViewSet
|
from rubricks.views import RubricViewSet
|
||||||
from api.views import FetchAndServeFile
|
from api.views import FetchAndServeFile
|
||||||
|
from audio.views import SongViewSet
|
||||||
|
|
||||||
|
|
||||||
router = routers.DefaultRouter()
|
router = routers.DefaultRouter()
|
||||||
router.register(r'news', newsViews.NewsViewSet)
|
router.register(r'news', newsViews.NewsViewSet)
|
||||||
#router.register(r'profiles', ProfileViewSet, basename='profiles')
|
|
||||||
router.register(r'teams', TeamViewSet, basename='teams')
|
router.register(r'teams', TeamViewSet, basename='teams')
|
||||||
router.register(r'rubriks', RubricViewSet, basename='rubriks')
|
router.register(r'rubriks', RubricViewSet, basename='rubriks')
|
||||||
|
router.register(r'song', SongViewSet, basename='song')
|
||||||
router.register(r'fetchandservefile', FetchAndServeFile, basename='fetchandservefile')
|
router.register(r'fetchandservefile', FetchAndServeFile, basename='fetchandservefile')
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('api/admin/', admin.site.urls),
|
path('api/admin/', admin.site.urls),
|
||||||
#path('api/fetch-file/<str:station>/<str:song_id>/', FetchAndServeFile.as_view(), name='fetch-file'),
|
#path('api/fetch-file/<str:station>/<str:song_id>/', FetchAndServeFile.as_view(), name='fetch-file'),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue