def get(self, request): username = request.query_params.get('username', None) if username: found_users = User.objects.filter(username__istartswith=username) serializer = ListUserSerializer(found_users, many=True) return Response(data=serializer.data, status=status.HTTP_200_OK) else: return Response(status=status.HTTP_400_BAD_REQUEST)
def get(self, request, image_id): """like 유저 리스트를 가져온다""" likes = Like.objects.filter(image_id=image_id) likes_creator_ids = likes.values('creator_id') like_users = User.objects.filter(id__in=likes_creator_ids) serializer = ListUserSerializer(like_users, many=True) return Response(data=serializer.data, status=status.HTTP_200_OK)
class NotificationSerializer(serializers.ModelSerializer): creator = ListUserSerializer() image = SmallImageSerializer() comment = CommentSerializer() class Meta: model = Notification fields = '__all__'
def get(self, request, username): user = get_object_or_404(User, username=username) serializer = ListUserSerializer(user.following.all(), many=True) return Response(data=serializer.data, status=status.HTTP_200_OK)
def get(self, request): users = User.objects.all().order_by('-date_joined')[:5] serializer = ListUserSerializer(users, many=True) return Response(data=serializer.data, status=status.HTTP_200_OK)