1.获取积分商品列表
1.在apps/ad/views.py内新建获取积分商品列表类:
class GetPrize(APIView): """ 获取奖品 """ renderer_classes = [JSONRenderer] # 渲染器 def get(self,request): token = request.GET.get(\'token\') page = request.GET.get(\'page\') sheng = request.GET.get(\'sheng\') shi = request.GET.get(\'shi\') xian = request.GET.get(\'xian\') user = UserProfile.objects.filter(token=token).first() if user and page: page=int(page) if sheng: # 全省 num = Area.objects.filter(name=sheng).first().num re_list = Prize.objects.filter(area__num__gt=num,area__num__lt=(num+10000)).order_by(\'-add_time\')[0:(10 * page)] re=PrizeModelSerializer(re_list,many=True) return Response(re.data) elif shi: # 全市 num = Area.objects.filter(name=shi).first().num # print(num) re_list = Prize.objects.filter(area__num__gte=num, area__num__lt=(num + 100)).order_by(\'-add_time\')[0:(10 * page)] re = PrizeModelSerializer(re_list, many=True) return Response(re.data) elif xian: # 全县 num = Area.objects.filter(name=xian).first().num # print(num) re_list = Prize.objects.filter(area__num=num).order_by(\'-add_time\')[0:(10 * page)] re = PrizeModelSerializer(re_list, many=True) return Response(re.data) else: re_list = Prize.objects.all().order_by(\'-add_time\')[0:(10 * page)] re = PrizeModelSerializer(re_list, many=True) return Response(re.data) else: return HttpResponse(\'参数不足\')
2.在apps/ad/urls.py内配置路由:
from django.urls import path from .views import GetCategory,CreateAdOrShop,UpLoadImg,GetPubGoods,GetGoodDesc,GetUserGoods,DelUserGood,EditGood,DelImg,GetPrize urlpatterns = [ path(\'getcategory/\',GetCategory.as_view()), path(\'createadorshop/\',CreateAdOrShop.as_view()), path(\'uploadimg/\',UpLoadImg.as_view()), path(\'getpubgoods/\',GetPubGoods.as_view()), path(\'getgooddesc/\',GetGoodDesc.as_view()), path(\'getusergoods/\',GetUserGoods.as_view()), path(\'delusergood/\',DelUserGood.as_view()), path(\'editgood/\',EditGood.as_view()), path(\'delimg/\',DelImg.as_view()), path(\'getprize/\',GetPrize.as_view()), ]
2.获取积分奖品详情
1.在apps/ad/views.py中新建GetPrizeDesc类:
class GetPrizeDesc(APIView): """ 获取奖品详情 """ renderer_classes = [JSONRenderer] # 渲染器 def get(self, request): token = request.GET.get(\'token\') id=request.GET.get(\'prizeid\') user = UserProfile.objects.filter(token=token).first() if user and id: id=int(id) re_obj=Prize.objects.filter(id=id).first() re=PrizeModelSerializer(re_obj) return Response(re.data) else: return HttpResponse(\'参数不足\')
2.在apps/ad/urls.py内配置路由
from django.urls import path from .views import GetCategory,CreateAdOrShop,UpLoadImg,GetPubGoods,GetGoodDesc,GetUserGoods,DelUserGood,EditGood,DelImg,GetPrize,GetPrizeDesc urlpatterns = [ path(\'getcategory/\',GetCategory.as_view()), path(\'createadorshop/\',CreateAdOrShop.as_view()), path(\'uploadimg/\',UpLoadImg.as_view()), path(\'getpubgoods/\',GetPubGoods.as_view()), path(\'getgooddesc/\',GetGoodDesc.as_view()), path(\'getusergoods/\',GetUserGoods.as_view()), path(\'delusergood/\',DelUserGood.as_view()), path(\'editgood/\',EditGood.as_view()), path(\'delimg/\',DelImg.as_view()), path(\'getprize/\',GetPrize.as_view()), path(\'getprizedesc/\',GetPrizeDesc.as_view()), ]
请发表评论