spradio-server-django/savepointradio/api/serializers/profiles.py

68 lines
1.6 KiB
Python
Raw Normal View History

2018-04-05 14:59:30 +00:00
from django.contrib.auth import get_user_model
2018-04-06 16:24:13 +00:00
from rest_framework.serializers import (IntegerField, ModelSerializer,
Serializer)
2018-04-05 14:59:30 +00:00
2018-04-09 16:11:15 +00:00
from profiles.models import RadioProfile, SongRequest, Rating
from .radio import SongMinimalSerializer
2018-04-05 14:59:30 +00:00
User = get_user_model()
class BasicUserSerializer(ModelSerializer):
class Meta:
model = User
fields = ('id', 'name', 'is_staff')
class FullUserSerializer(ModelSerializer):
class Meta:
model = User
fields = ('id', 'email', 'name', 'is_staff', 'is_active', 'last_login')
class BasicProfileSerializer(ModelSerializer):
user = BasicUserSerializer()
class Meta:
model = RadioProfile
fields = ('id', 'user')
class FullProfileSerializer(BasicProfileSerializer):
user = FullUserSerializer()
2018-04-06 16:24:13 +00:00
class FavoriteSongSerializer(Serializer):
song = IntegerField()
class RateSongSerializer(Serializer):
value = IntegerField(min_value=0, max_value=5, required=False)
class HistorySerializer(ModelSerializer):
profile = BasicProfileSerializer()
song = SongMinimalSerializer()
class Meta:
model = SongRequest
fields = ('created_date', 'played_at', 'profile', 'song')
2018-04-09 16:11:15 +00:00
class BasicProfileRatingsSerializer(ModelSerializer):
song = SongMinimalSerializer()
2018-04-09 16:11:15 +00:00
class Meta:
model = Rating
fields = ('created_date', 'song', 'value')
class BasicSongRatingsSerializer(ModelSerializer):
profile = BasicProfileSerializer()
class Meta:
model = Rating
fields = ('created_date', 'profile', 'value')