views.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:BackendAllStars 作者: belatrix 项目源码 文件源码
def stars_employee_list_group_by_category(request, employee_id):
    """
    Returns stars list from employee grouped by categories
    ---
    serializer: stars.serializers.StarEmployeeCategoriesSerializer
    responseMessages:
    - code: 401
      message: Unauthorized. Authentication credentials were not provided. Invalid token.
    - code: 403
      message: Forbidden, authentication credentials were not provided
    - code: 404
      message: Not found
    """
    if request.method == 'GET':
        employee = get_object_or_404(Employee, pk=employee_id)
        employee_stars = Star.objects.filter(to_user=employee).values(
            'category__pk',
            'category__name').annotate(num_stars=Count('category')).order_by('-num_stars', 'category__name')
        paginator = PageNumberPagination()
        result = paginator.paginate_queryset(employee_stars, request)
        serializer = StarEmployeeCategoriesSerializer(result, many=True)
        return paginator.get_paginated_response(serializer.data)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号