Supports profile updates
only background for now, but hey.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
from .track import TrackSerializer
|
from .track import *
|
||||||
from .artist import ArtistSerializer
|
from .artist import *
|
||||||
from .user import UserSerializer
|
from .user import *
|
||||||
from .album import AlbumSerializer
|
from .album import *
|
||||||
from .profile import ProfileSerializer, BackgroundSerializer
|
from .profile import *
|
||||||
from .vote import *
|
from .vote import *
|
||||||
|
|||||||
@@ -12,3 +12,9 @@ class ProfileSerializer(serializers.ModelSerializer):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = Profile
|
model = Profile
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
|
class ProfileUpdateSerializer(serializers.ModelSerializer):
|
||||||
|
background = serializers.PrimaryKeyRelatedField(many=False, queryset=Background.objects.all())
|
||||||
|
class Meta:
|
||||||
|
model = Profile
|
||||||
|
fields = ['background']
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from pickle import BUILD
|
|||||||
from playlist import serializers
|
from playlist import serializers
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from playlist.serializers import ProfileSerializer, BackgroundSerializer
|
from playlist.serializers import ProfileSerializer, ProfileUpdateSerializer, BackgroundSerializer
|
||||||
from playlist.models import Profile, Background
|
from playlist.models import Profile, Background
|
||||||
|
|
||||||
class ProfileDetailView(APIView):
|
class ProfileDetailView(APIView):
|
||||||
@@ -11,6 +11,14 @@ class ProfileDetailView(APIView):
|
|||||||
serializer = ProfileSerializer(profile)
|
serializer = ProfileSerializer(profile)
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
|
def put(self, request, id):
|
||||||
|
profile = Profile.objects.get(pk=id)
|
||||||
|
serializer = ProfileUpdateSerializer(profile, data=request.data)
|
||||||
|
serializer.is_valid()
|
||||||
|
serializer.save()
|
||||||
|
return Response(serializer.data)
|
||||||
|
#return Response()
|
||||||
|
|
||||||
class BackgroundListView(APIView):
|
class BackgroundListView(APIView):
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
backgrounds = Background.objects.all()
|
backgrounds = Background.objects.all()
|
||||||
|
|||||||
Reference in New Issue
Block a user