cfr #121 Co-authored-by: Christophe Siraut <d@tobald.eu.org> Co-authored-by: bkfox <thomas bkfox net> Co-authored-by: Thomas Kairos <thomas@bkfox.net> Reviewed-on: #131 Co-authored-by: Chris Tactic <ctactic@noreply.git.radiocampus.be> Co-committed-by: Chris Tactic <ctactic@noreply.git.radiocampus.be>
48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
from rest_framework import serializers
|
|
|
|
from filer.models.imagemodels import Image
|
|
from taggit.serializers import TaggitSerializer, TagListSerializerField
|
|
|
|
from ..models import Track, UserSettings
|
|
|
|
__all__ = ("ImageSerializer", "TrackSerializer", "UserSettingsSerializer")
|
|
|
|
|
|
class ImageSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = Image
|
|
fields = "__all__"
|
|
|
|
|
|
class TrackSerializer(TaggitSerializer, serializers.ModelSerializer):
|
|
tags = TagListSerializerField()
|
|
|
|
class Meta:
|
|
model = Track
|
|
fields = (
|
|
"pk",
|
|
"artist",
|
|
"title",
|
|
"album",
|
|
"year",
|
|
"position",
|
|
"info",
|
|
"tags",
|
|
"episode",
|
|
"sound",
|
|
"timestamp",
|
|
)
|
|
|
|
|
|
class UserSettingsSerializer(serializers.ModelSerializer):
|
|
# TODO: validate fields values (tracklist_editor_columns at least)
|
|
class Meta:
|
|
model = UserSettings
|
|
fields = ("tracklist_editor_columns", "tracklist_editor_sep")
|
|
|
|
def create(self, validated_data):
|
|
user = self.context.get("user")
|
|
if user:
|
|
validated_data["user_id"] = user.id
|
|
return super().create(validated_data)
|