profiles: use of OneToOneField to access profile through user
This commit is contained in:
@ -4,7 +4,6 @@ from rest_framework import permissions, status
|
||||
from rest_framework.authentication import SessionAuthentication
|
||||
|
||||
from django.utils.translation import gettext as _
|
||||
from django.db.models import Q
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from ..models import ProfileModel, FriendModel
|
||||
@ -16,11 +15,7 @@ class GetFriendsView(APIView):
|
||||
authentication_classes = (SessionAuthentication,)
|
||||
|
||||
def get(self, request):
|
||||
query = ProfileModel.objects.filter(user=request.user)
|
||||
if not query.exists():
|
||||
return Response(status=status.HTTP_400_BAD_REQUEST)
|
||||
friends = query[0].get_friends()
|
||||
return Response(ProfileSerializer(friends, many=True).data)
|
||||
return Response(ProfileSerializer(request.user.profilemodel.get_friends(), many=True).data)
|
||||
|
||||
|
||||
class EditFriendView(APIView):
|
||||
@ -28,7 +23,7 @@ class EditFriendView(APIView):
|
||||
authentication_classes = (SessionAuthentication,)
|
||||
|
||||
def get_object(self):
|
||||
return ProfileModel.objects.get(pk=self.request.user.pk)
|
||||
return self.request.user.profilemodel
|
||||
|
||||
def post(self, request, pk=None):
|
||||
user_profile = self.get_object()
|
||||
|
Reference in New Issue
Block a user