• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

广告小程序后端开发(12.个人中心:获取价目表,删除广告或店铺) ...

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1.在apps/trade/views.py中新建获取价目表的类GetPrice:

from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.renderers import JSONRenderer,BrowsableAPIRenderer
from .serializers import PriceModelSerializer,OrderModelSerializer,ShoppingCarModelSerializer
from .models import Price,Order,ShoppingCar

# Create your views here.


class GetPrice(APIView):
    """
    获取价格表数据
    """
    renderer_classes = [JSONRenderer]  # 渲染器

    def get(self,request):
        price_list = Price.objects.all()
        re = PriceModelSerializer(price_list, many=True)
        return Response(re.data)

2.在apps/trade目录下新建urls.py配置路由:

from django.urls import path
from .views import GetPrice

urlpatterns = [
    path('getprice/',GetPrice.as_view())
]

3.在gg/urls.py中加入trade的urls.py代码:

from django.urls import path,include
from django.views.static import serve
from gg.settings import MEDIA_ROOT

import xadmin

urlpatterns = [
    #path('admin/', admin.site.urls),
    path('media/<path:path>',serve,{'document_root':MEDIA_ROOT}),
    path('xadmin/', xadmin.site.urls),
    path('users/',include('users.urls')),
    path('ad/',include('ad.urls')),
    path('trade/',include('trade.urls'))
]

2.删除广告或店铺

1.在apps/ad/views.py中新建类DelUserGood:

#……
from user_operation.models import Message

#……
class DelUserGood(APIView):
    """删除广告或店铺"""
    renderer_classes = [JSONRenderer]  # 渲染器

    def get(self,request):
        token = request.GET.get('token')
        user = UserProfile.objects.filter(token=token).first()
        good_id=request.GET.get('goodid')
        # print(good_id)
        if user and good_id:
            good_id = int(good_id)
            good=Good.objects.filter(user=user,id=good_id).first()
            # print(good)
            title=good.title
            msg=Message()
            msg.user=user
            msg.content="您成功删除了"+title
            msg.save()
            Good.objects.filter(user=user,id=good_id).delete()
            return HttpResponse('200')
        else:
            return HttpResponse('参数不正确')

2.在apps/ad/urls.py中配置路由:

from django.urls import path
from .views import GetCategory,CreateAdOrShop,UpLoadImg,GetPubGoods,GetGoodDesc,GetUserGoods,DelUserGood

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()),
]

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
支付宝小程序iconfont兼容性问题发布时间:2022-07-18
下一篇:
小程序倒计时遇到的问题发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap