1、修改goods/views下SKUHistoryView类
class SKUHistoryView(CreateAPIView):
"""
保存和获取用户浏览历史记录
"""
serializer_class = SKUHistorySeriazliers
def get(self, request):
# 1、获取用户对象
user = request.user
# 2、查询redis获取sku_id
conn = get_redis_connection('history')
sku_ids = conn.lrange('history_%s' % user.id, 0, 5) # [3,1,2]
# 3、根据sku_id查询商品对象
skus = SKU.objects.filter(id__in=sku_ids) #
# 4、序列化返回商品信息
ser = CategoriesListSerialziers(skus, many=True)
return Response(ser.data)