nu met een hoeveelheid meer profile
This commit is contained in:
@@ -2,3 +2,4 @@ from .track import TrackSerializer
|
|||||||
from .artist import ArtistSerializer
|
from .artist import ArtistSerializer
|
||||||
from .user import UserSerializer
|
from .user import UserSerializer
|
||||||
from .album import AlbumSerializer
|
from .album import AlbumSerializer
|
||||||
|
from .profile import ProfileSerializer, BackgroundSerializer
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
from playlist.models import Profile, Background
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
class BackgroundSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Background
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
class ProfileSerializer(serializers.ModelSerializer):
|
||||||
|
background = BackgroundSerializer()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Profile
|
||||||
|
fields = '__all__'
|
||||||
@@ -1,7 +1,17 @@
|
|||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
class UserSerializer(serializers.ModelSerializer):
|
class UserSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
# Add explicit reverse lookup to profile
|
||||||
|
profile = serializers.HyperlinkedRelatedField(
|
||||||
|
view_name='api-profile',
|
||||||
|
lookup_field='id',
|
||||||
|
read_only=True
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
fields = ['id', 'username', 'email']
|
fields = ['url', 'id', 'username', 'email', 'profile']
|
||||||
|
extra_kwargs = {
|
||||||
|
'url': {'view_name': 'api-user', 'lookup_field': 'id'}
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ urlpatterns = [
|
|||||||
path('api/artist', views.ArtistListView.as_view(), name="api-artists"),
|
path('api/artist', views.ArtistListView.as_view(), name="api-artists"),
|
||||||
path('api/users', views.UserListView.as_view(), name="api-users"),
|
path('api/users', views.UserListView.as_view(), name="api-users"),
|
||||||
path('api/user/<int:id>', views.UserDetailView.as_view(), name="api-user"),
|
path('api/user/<int:id>', views.UserDetailView.as_view(), name="api-user"),
|
||||||
|
path('api/profile/<int:id>', views.ProfileDetailView.as_view(), name="api-profile"),
|
||||||
|
path('api/profile/background', views.BackgroundListView.as_view(), name="api-backgrounds"),
|
||||||
|
path('api/profile/background/<int:id>', views.BackgroundDetailView.as_view(), name="api-background"),
|
||||||
path('api/album/<id>', views.AlbumDetailView.as_view(), name="api-album"),
|
path('api/album/<id>', views.AlbumDetailView.as_view(), name="api-album"),
|
||||||
path('api/album', views.AlbumListView.as_view(), name="api-albums"),
|
path('api/album', views.AlbumListView.as_view(), name="api-albums"),
|
||||||
path('track/', views.NominateView.as_view(), name="nominate"),
|
path('track/', views.NominateView.as_view(), name="nominate"),
|
||||||
|
|||||||
@@ -4,3 +4,4 @@ from .api.track import *
|
|||||||
from .api.artist import *
|
from .api.artist import *
|
||||||
from .api.user import *
|
from .api.user import *
|
||||||
from .api.album import *
|
from .api.album import *
|
||||||
|
from .api.profile import *
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
from pickle import BUILD
|
||||||
|
from playlist import serializers
|
||||||
|
from rest_framework.views import APIView
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from rest_framework.authentication import SessionAuthentication
|
||||||
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
from playlist.serializers import ProfileSerializer, BackgroundSerializer
|
||||||
|
from playlist.models import Profile, Background
|
||||||
|
|
||||||
|
class ProfileDetailView(APIView):
|
||||||
|
authentication_classes = [SessionAuthentication]
|
||||||
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
|
def get(self, request, id):
|
||||||
|
profile = Profile.objects.get(pk=id)
|
||||||
|
serializer = ProfileSerializer(profile)
|
||||||
|
return Response(serializer.data)
|
||||||
|
|
||||||
|
class BackgroundListView(APIView):
|
||||||
|
authentication_classes = [SessionAuthentication]
|
||||||
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
backgrounds = Background.objects.all()
|
||||||
|
serializer = BackgroundSerializer(backgrounds, many=True)
|
||||||
|
return Response(serializer.data)
|
||||||
|
|
||||||
|
class BackgroundDetailView(APIView):
|
||||||
|
authentication_classes = [SessionAuthentication]
|
||||||
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
|
def get(self, request, id):
|
||||||
|
background = Background.objects.get(pk=id)
|
||||||
|
serializer = BackgroundSerializer(background)
|
||||||
|
return Response(serializer.data)
|
||||||
@@ -10,7 +10,7 @@ class UserListView(APIView):
|
|||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
users = User.objects.all()
|
users = User.objects.all()
|
||||||
serializer = UserSerializer(users, many=True)
|
serializer = UserSerializer(users, many=True, context={'request': request})
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
class UserDetailView(APIView):
|
class UserDetailView(APIView):
|
||||||
@@ -18,5 +18,5 @@ class UserDetailView(APIView):
|
|||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
def get(self, request, id):
|
def get(self, request, id):
|
||||||
user = User.objects.get(pk=id)
|
user = User.objects.get(pk=id)
|
||||||
serializer = UserSerializer(user)
|
serializer = UserSerializer(user, context={'request': request})
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|||||||
Reference in New Issue
Block a user