32 lines
982 B
Python
32 lines
982 B
Python
from playlist.models import Artist
|
|
from rest_framework import serializers
|
|
from drf_spectacular.utils import extend_schema_serializer, OpenApiExample
|
|
|
|
@extend_schema_serializer(
|
|
examples=[
|
|
OpenApiExample(
|
|
'Daft Punk',
|
|
value = {
|
|
"id": "4tZwfgrHOc3mvqYlEYSvVi",
|
|
"name": "Daft Punk",
|
|
"url": "http://127.0.0.1:8001/api/artist/4tZwfgrHOc3mvqYlEYSvVi"
|
|
}
|
|
),
|
|
OpenApiExample(
|
|
'コリッキー',
|
|
value = {
|
|
"id": "307y5sbPNvRpXjBcZgS25q",
|
|
"name": "コリッキー",
|
|
"url": "http://127.0.0.1:8001/api/artist/307y5sbPNvRpXjBcZgS25q"
|
|
}
|
|
)
|
|
]
|
|
)
|
|
class ArtistSerializer(serializers.HyperlinkedModelSerializer):
|
|
class Meta:
|
|
model = Artist
|
|
fields = ['id', 'name', 'url']
|
|
extra_kwargs = {
|
|
'url': {'view_name': 'api-artist', 'lookup_field': 'id'},
|
|
}
|