传回后台的需求是?is_new = true。但返回的数据都是is_new = false什么情况
来源:11-2 新品功能接口开发
慕斯卡8313365
2020-04-19
写回答
4回答
-
这个是否配置了呢?
012020-04-23 -
慕斯卡8313365
提问者
2020-04-21
class GoodsCategorySerializer(serializers.ModelSerializer): """ 序列化商品一级种类 """ sub_cat = GoodsCategorySerializer2(many=True) class Meta: model = GoodsCategory fields = '__all__' class GoodsSerializer(serializers.ModelSerializer): """ 序列化商品 """ category = GoodsCategorySerializer() # 覆写modelform, 用外键的model替换外键。注意,后缀是Serializer images = GoodsImageSerializer(many=True) # many=True 一对多关系。将images配置到商品的serializers里 class Meta: model = Goods fields = '__all__' # field完全copy Goods
00 -
慕斯卡8313365
提问者
2020-04-21
class GoodsListViewset(CacheResponseMixin, mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet): """ 利用Viewsets进一步优化,与urls中的Router配合 商品列表页 """ throttle_classes = [UserRateThrottle, AnonRateThrottle] # 用户限速通过用户ID,匿名用户(未登录)限速通过IP地址 queryset = Goods.objects.all() # 属性 serializer_class = GoodsSerializer pagination_class = GoodsPagination # 分页 def retrieve(self, request, *args, **kwargs): instance = self.get_object() instance.click_num += 1 instance += 1 serializer = self.get_serializer(instance) return Response(serializer.data) # authentication_classes = (TokenAuthentication, ) # 设置局部认证,列表页不需要登陆后访问,所以需注释掉 filter_backends = [DjangoFilterBackend, filters.SearchFilter, filters.OrderingFilter] # 过滤,搜索,排序 # filterset_fields = ['name', 'shop_price'] # drf中的过滤功能 #利用django-filter中的过滤功能,filterset_class实现复杂功能过滤 filterset_class = GoodsFilter #利用drf 的filters 实现搜索和排序 search_fields = ['name', 'goods_brief', 'goods_desc'] ordering_fields = ['sold_num', 'shop_price']
00 -
bobby
2020-04-21
后台的viewset的源码截图我看看
012020-04-21
Python前后端分离开发Vue+Django REST framework实战
Django REST framework课程视频,RESTFul API前后端分离开发
2873 学习 · 2461 问题
相似问题