class Search(APIView):
def get(self, request, format=None):
hashtags = request.query_params.get('hashtags',None)
if hashtags is not None:
hashtags = hashtags.split(",")
images = models.Image.objects.filter(
tags__name__in=hashtags).distinct()
serializer = serializers.CountImageSerializer(images, many=True)
return Response(data=serializer.data, status=status.HTTP_200_OK)
else:
return Response(status=status.HTTP_400_BAD_REQUEST)
지난 포스팅에서
hastag를 뽑았다
그리고 이미지를 해시태그를 통하여 검색하게 될 것인데
filter메소드를 이용하여
해시태그를 구분하였다,
'BackEnd > Django' 카테고리의 다른 글
[Django]Notification API (0) | 2018.11.07 |
---|---|
[Django]Notification App 만들기 (0) | 2018.11.06 |
[Django]해시태그 search 1 (0) | 2018.11.05 |
[Django]Following&Follower List만들기! (0) | 2018.11.05 |
[Django] User Profile (0) | 2018.11.05 |