如何通过在列表上计算相关项目来更新实例列表?

我想使用链接到类别的书籍总数更新实例列表。响应如下。例如,我有一些书籍链接到“历史记录”。每当我拨打电话时,如何更新列表中的总数?

[
    {
        "id": 1,
        "category_name": "History",
        "category_code": "his",
        "is_tab": true,
        "add_time": "2020-03-02T15:56:58.469917Z",
        "total_number": 0
    },
    {
        "id": 2,
        "category_name": "Romance",
        "category_code": "ROM",
        "is_tab": true,
        "add_time": "2020-05-22T17:02:47.919479Z",
        "total_number": 0
    },
    {
        "id": 3,
        "category_name": "Sci-fic",
        "category_code": "S-F",
        "is_tab": true,
        "add_time": "2020-05-22T17:04:57.896846Z",
        "total_number": 0
    }
]

序列化器

class CategorySerializer(serializers.ModelSerializer):
    class Meta:
        model = BookCategory
        fields = ('id', 'category_name', 'category_code', "is_tab", 'add_time', 'total_number')

view.py

class BookCategoryDetailView(ListCreateAPIView, RetrieveModelMixin):
    queryset = BookCategory.objects.all()
    serializer_class = CategorySerializer