class UserDetailSerilizer(serializers.ModelSerializer):
    """
        用户收藏内容
    """
    goods = GoodsSerializer()
    class Meta:
        model = UserFav
        fields = ('goods',)
Exemple #2
0
class UserFavListSerializer(serializers.ModelSerializer):
    """
    用于查看用户收藏
    """
    goods = GoodsSerializer()

    class Meta:
        model = UserFav
        fields = ("goods", "id")
Exemple #3
0
class UserFavDetailSerializer(serializers.ModelSerializer):
    '''
    用户收藏详情
    '''

    #通过商品id获取收藏的商品,需要嵌套商品的序列化
    goods = GoodsSerializer()

    class Meta:
        model = UserFav
        fields = ('goods', 'id')
Exemple #4
0
class ShoppingCartDetailSerializer(serializers.ModelSerializer):
    """
        购物车
    """
    user = serializers.HiddenField(default=serializers.CurrentUserDefault())
    nums = serializers.IntegerField()
    goods = GoodsSerializer()

    class Meta:
        model = ShoppingCart
        fields = '__all__'
Exemple #5
0
class OrderDetailSerializer(serializers.ModelSerializer):
    """
        订单商品
    """
    goods = GoodsSerializer()

    alipay_url = serializers.SerializerMethodField(read_only=True)

    def get_alipay_url(self, obj):
        aplipay = AliPay(appid=ALIPAY['APPID'],
                         app_notify_url=ALIPAY['NOTIFY_URL'],
                         return_url=ALIPAY['RETURN_URL'],
                         debug=ALIPAY['DEBUG'],
                         app_private_key_path=ALIPAY['APP_PRIVATE_KEY'],
                         alipay_public_key_path=ALIPAY['ALIPAY_PUBLIC_KEY'])
        url = aplipay.direct_pay(subject=obj.order_sn,
                                 out_trade_no=obj.order_sn,
                                 total_amount=obj.order_mount)
        ret_url = ALIPAY['ALIPAY_URL'] + '?{data}'.format(data=url)
        return ret_url

    class Meta:
        model = OrderGoods
        fields = '__all__'
class UserFavDetailSerializer(serializers.ModelSerializer):
    goods = GoodsSerializer()

    class Meta:
        model = UserFav
        fields = ("goods", "id")
Exemple #7
0
class OrderGoodsSerializer(serializers.ModelSerializer):
    goods = GoodsSerializer(many=False)

    class Meta:
        model = OrderGoods
        fields = "__all__"
Exemple #8
0
class ShoppingCartDetailSerializer(serializers.ModelSerializer):
    goods = GoodsSerializer(many=False)

    class Meta:
        model = ShoppingCart
        fields = "__all__"
Exemple #9
0
class OrderGoodsDetailSerializer(serializers.ModelSerializer):
    goods = GoodsSerializer()

    class Meta:
        model = OrderGoods
        fields = "__all__"
Exemple #10
0
 def get(self, request, format=None):
     goods = Goods.objects.all()[:10]
     goods_serializer = GoodsSerializer(goods, many=True)  # 因为是goods是list,多条数据要增加many=True
     return Response(goods_serializer.data)
Exemple #11
0
class UserFavDetailSerializer(serializers.ModelSerializer):
    goods = GoodsSerializer()

    class Meta:
        model = UserFav
        fields = ('goods', 'id')
Exemple #12
0
class UserFavDetailSerializer(serializers.ModelSerializer):
    goods = GoodsSerializer()

    class Meta:
        model = UserFav
        fields = "__all__"