feat(problem tag): 支持模糊搜索

This commit is contained in:
helsonxiao 2020-11-29 14:01:12 +08:00
parent a4a66d2271
commit 515f422a2d
1 changed files with 5 additions and 1 deletions

View File

@ -9,7 +9,11 @@ from contest.models import ContestRuleType
class ProblemTagAPI(APIView):
def get(self, request):
tags = ProblemTag.objects.annotate(problem_count=Count("problem")).filter(problem_count__gt=0)
qs = ProblemTag.objects
keyword = request.GET.get('keyword')
if keyword:
qs = ProblemTag.objects.filter(name__icontains=keyword)
tags = qs.annotate(problem_count=Count("problem")).filter(problem_count__gt=0)
return self.success(TagSerializer(tags, many=True).data)