48 lines
1.8 KiB
Python
48 lines
1.8 KiB
Python
from os import extsep
|
|
from django.db.models.functions import Extract
|
|
from playlist.models import Album
|
|
from rest_framework import serializers
|
|
from drf_spectacular.utils import extend_schema_serializer, OpenApiExample
|
|
|
|
@extend_schema_serializer(
|
|
examples = [
|
|
OpenApiExample(
|
|
name='Album Example',
|
|
value = {
|
|
"url": "http://muzak.hoekveen.net/api/album/7MejfRSNnrpcLZIxkeZDqR",
|
|
"name": "Leftoverture (Expanded Edition)",
|
|
"album_type": "album",
|
|
"total_tracks": 10,
|
|
"image": "http://127.0.0.1:8001/albums/Leftoverture_Expanded_Edition.png",
|
|
"image_url": "https://i.scdn.co/image/ab67616d0000b2731be40e44db112e123e5e8b51",
|
|
"artists": [
|
|
"http://127.0.0.1:8001/api/artist/2hl0xAkS2AIRAu23TVMBG1"
|
|
]
|
|
}
|
|
),
|
|
OpenApiExample(
|
|
name = 'Multiple artist single',
|
|
value = {
|
|
"url": "http://127.0.0.1:8001/api/album/1pHD8AFu4z1CvuTPjZFOFi",
|
|
"name": "ラビリンス",
|
|
"album_type": "single",
|
|
"total_tracks": 4,
|
|
"image": None,
|
|
"image_url": "https://i.scdn.co/image/ab67616d0000b2731607d3aa3a69ca0e1ffbe26b",
|
|
"artists": [
|
|
"http://127.0.0.1:8001/api/artist/4ZX8Wr8KHHrW7radu6IwYG",
|
|
"http://127.0.0.1:8001/api/artist/4d2zOuYJHBPJTpVblHEKJb"
|
|
]
|
|
}
|
|
)
|
|
]
|
|
)
|
|
class AlbumSerializer(serializers.HyperlinkedModelSerializer):
|
|
class Meta:
|
|
model = Album
|
|
fields = '__all__'
|
|
extra_kwargs = {
|
|
'url': {'view_name': 'api-album', 'lookup_field': 'id'},
|
|
'artists': {'view_name': 'api-artist', 'lookup_field': 'id'},
|
|
}
|