class EditGood(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() tabcur = request.GET.get('tabcur') if tabcur: tabcur = int(tabcur) + 1 good.type=tabcur title = request.GET.get('title') if title: good.title=title desc = request.GET.get('desc') if desc: good.desc=desc mobile = request.GET.get('mobile') if mobile: good.mobile=mobile address = request.GET.get('address') if address: good.address=address c1 = request.GET.get('c1') c2 = request.GET.get('c2') if c1 and c2: cat1 = Category.objects.filter(name=c1).first() cat2 = Category.objects.filter(name=c2, parent_category=cat1).first() good.category = cat2 good.stage=1 good.save() msg = Message() msg.user = user msg.content = "您成功修改了" + title msg.save() return HttpResponse(200) else: return HttpResponse('參數不足')
from django.urls import path from .views import GetCategory,CreateAdOrShop,UpLoadImg,GetPubGoods,GetGoodDesc,GetUserGoods,DelUserGood,EditGood 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()), ]
class DelImg(APIView): """ 刪除圖片 """ renderer_classes = [JSONRenderer] # 渲染器 authentication_classes = [Authtication, ] def post(self, request): id=int(request.POST.get('id')) good=Good.objects.filter(id=id).first() Images.objects.filter(good=good).delete() return HttpResponse(200)
from django.urls import path from .views import GetCategory,CreateAdOrShop,UpLoadImg,GetPubGoods,GetGoodDesc,GetUserGoods,DelUserGood,EditGood,DelImg 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()), ]