(二十六)拍卖专场相关的接口

Posted a438842265

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了(二十六)拍卖专场相关的接口相关的知识,希望对你有一定的参考价值。

1. 拍卖专场的接口

url(r^auction/$, auction.AuctionView.as_view()),

class AuctionModelView(serializers.ModelSerializer): status = serializers.CharField(source=get_status_display) preview_start_time = serializers.DateTimeField(format="%Y-%m-%d") goods = serializers.SerializerMethodField() class Meta: model = models.Auction # fields = "__all__" fields = [id, title, cover, status, preview_start_time, look_count, goods_count, total_price, bid_count, goods] def get_goods(self, obj): queryset = models.AuctionItem.objects.filter(auction=obj)[0:5] return [row.cover for row in queryset] class AuctionView(ListAPIView): """ 拍卖专场接口 """ # queryset = models.Auction.objects.filter(status__gt=1).order_by(‘id‘) queryset = models.Auction.objects.filter(status__gt=0).order_by(id) serializer_class = AuctionModelView # 分页接口 # filter_backends = [MinFilterBackend, MaxFilterBackend] # pagination_class = OldBoyLimitPagination

2. 拍卖专场详细

先获取专场详细---在里面获取商品信息在写一个序列化循每一个商品的信息
url(r^auction/(?P<pk>d+)/$, auction.AuctionDetailView.as_view()),

class AuctionDetailItemModelSerializer(serializers.ModelSerializer): is_deposit = serializers.SerializerMethodField() class Meta: model = models.AuctionItem fields = [id, cover, status, reserve_price, highest_price, is_deposit] def get_is_deposit(self, obj): user_object = self.context[request].user if not user_object: return False return models.DepositRecord.objects.filter(user=user_object, item=obj, status=2, deposit_type=1).exists() class AuctionModelDetailView(serializers.ModelSerializer): goods = serializers.SerializerMethodField() # 检查是否缴纳保证金 is_deposit = serializers.SerializerMethodField() model = models.Auction fields = __all__ def get_goods(self, obj): item_object_list = models.AuctionItem.objects.filter(auction=obj)
      # 每个单品的信息 ser
= AuctionDetailItemModelSerializer(instance=item_object_list, many=True, context=self.context) return ser.data def get_is_deposit(self, obj): """ 检查是否已缴纳全场保证金 """ # 1. 没登陆,显示去缴纳保证金 user_object = self.context[request].user if not user_object: return False # 2. 去查看缴纳保证金记录的表中是否有此用户&此专场 return models.DepositRecord.objects.filter(user=user_object, auction=obj, status=2, item__isnull=True).exists() class AuctionDetailView(RetrieveAPIView): """ 拍卖列表详细页面 专场详细 """ queryset = models.Auction.objects.filter(status__gt=1) serializer_class = AuctionModelDetailView

3. 整合 拍卖专场和拍卖详细

    # ‘‘‘继承GenericViewSet要写get对应的是啥‘‘‘
    url(r^auction2/$, auction.Auction2View.as_view({get:list})),
    url(r^auction2/(?P<pk>d+)/$, auction.Auction2View.as_view({get:retrieve})),



class Auction2View(ListModelMixin, RetrieveModelMixin, GenericViewSet):
    queryset = models.Auction.objects.filter(status__gt=1).order_by(-id)
    serializer_class = AuctionModelSerializerView
    filter_backends = [MinFilterBackend, MaxFilterBackend, ]
    pagination_class = OldBoyLimitPagination

    def get_serializer_class(self):
        pk = self.kwargs.get(pk)
        if pk:
            return AuctionModelDetailView
        return AuctionModelSerializerView

↓ 对应的序列化
# ##############拍卖专场接口###################################
class AuctionModelSerializerView(serializers.ModelSerializer):
    status = serializers.CharField(source=get_status_display)
    preview_start_time = serializers.DateTimeField(format="%Y-%m-%d")

    goods = serializers.SerializerMethodField()

    class Meta:
        model = models.Auction
        # fields = "__all__"
        fields = [id, title, cover, status, preview_start_time,
                  look_count, goods_count, total_price, bid_count, goods]

    def get_goods(self, obj):
        queryset = models.AuctionItem.objects.filter(auction=obj)[0:5]
        return [row.cover for row in queryset]

# #######拍卖列表详细页面 专场详细##########################################

class AuctionDetailItemModelSerializer(serializers.ModelSerializer):
    is_deposit = serializers.SerializerMethodField()

    class Meta:
        model = models.AuctionItem
        fields = [id, cover, status, reserve_price, highest_price, is_deposit]

    def get_is_deposit(self, obj):
        user_object = self.context[request].user
        if not user_object:
            return False
        return models.DepositRecord.objects.filter(user=user_object, item=obj, status=2, deposit_type=1).exists()


class AuctionModelDetailView(serializers.ModelSerializer):
    goods = serializers.SerializerMethodField()
    # 检查是否缴纳保证金
    is_deposit = serializers.SerializerMethodField()

    model = models.Auction
    fields = __all__

    def get_goods(self, obj):
        # 每个单品信息
        item_object_list = models.AuctionItem.objects.filter(auction=obj)
        ser = AuctionDetailItemModelSerializer(instance=item_object_list, many=True, context=self.context)
        return ser.data

    def get_is_deposit(self, obj):
        """ 检查是否已缴纳全场保证金 """
        # 1. 没登陆,显示去缴纳保证金
        user_object = self.context[request].user
        if not user_object:
            return False
        # 2. 去查看缴纳保证金记录的表中是否有此用户&此专场
        return models.DepositRecord.objects.filter(user=user_object, auction=obj, status=2, item__isnull=True).exists()

 

以上是关于(二十六)拍卖专场相关的接口的主要内容,如果未能解决你的问题,请参考以下文章

企业分布式微服务云SpringCloud SpringBoot mybatis (二十六)集成apidoc

团队冲刺第二十六天

团队冲刺第二十六天

ERP合同管理(二十六)

代码安全 | 第二十六期:通过错误消息导致的信息暴露

python接口自动化测试二十六:使用pymysql模块链接数据库