예제 #1
0
 def get_queryset(self):
     search_text = self.request.query_params.get("search_text")
     queryset = self.queryset
     if search_text:
         vector = SearchVector("name", "district__name", "state__name")
         query = SearchQuery(get_psql_search_tokens(search_text),
                             search_type="raw")
         queryset = (self.queryset.annotate(
             search_text=vector, rank=SearchRank(
                 vector,
                 query)).filter(search_text=query).order_by("-rank"))
     return queryset
예제 #2
0
파일: facility.py 프로젝트: traviraj90/care
    def filter_queryset(self, request, queryset, view):
        if request.user.is_superuser or request.query_params.get("all") == "true":
            pass
        elif request.user.user_type >= User.TYPE_VALUE_MAP["DistrictLabAdmin"]:
            queryset = queryset.filter(district=request.user.district)
        else:
            queryset = queryset.filter(Q(created_by=request.user) | Q(users__id__exact=request.user.id))

        search_text = request.query_params.get("search_text")
        if search_text:
            vector = SearchVector("name", "district__name", "state__name")
            query = SearchQuery(get_psql_search_tokens(search_text), search_type="raw")
            queryset = (
                queryset.annotate(search_text=vector, rank=SearchRank(vector, query))
                .filter(search_text=query)
                .order_by("-rank")
            )
        return queryset