Пример #1
0
 def post(self, request, *args, **kwargs):
     item = Item.objects.get(id=kwargs['itemID'])
     form = ItemForm(request.POST, instance=item)
     if not form.is_valid():
         kwargs['form'] = form
         return super(ItemEdit, self).post(request, *args, **kwargs)
     item = form.save()
     if 'image' in request.FILES:
         if item.image!="":
             file_delete(item.image.split("/")[1],"item")
         item.image = file_put2(request.FILES['image'], item.id, 'item')
     if 'image2' in request.FILES:
         if item.image2!="":
             file_delete(item.image2.split("/")[1],"item2")
         item.image2 = file_put2(request.FILES['image2'], item.id, 'item2')
     item.save()
     messages.success(request, '商品:'+request.POST.get('name')+"已更新成功")        
     return redirect(reverse('control:item'))
Пример #2
0
 def post(self, request, *args, **kwargs):
     form = ItemForm(request.POST)
     
     if not form.is_valid():
         kwargs['form'] = form
         return super(ItemAdd, self).post(request, *args, **kwargs)
     item = form.save()
     if 'image' in request.FILES:
         item.image = file_put2(request.FILES['image'], item.id, 'item')
     if 'image2' in request.FILES:
         item.image2 = file_put2(request.FILES['image2'], item.id, 'item2')
     item.save()
         
     
     
     messages.success(request, '商品:'+request.POST.get('name')+"上架成功")
     
     return redirect(reverse('control:item'))
Пример #3
0
 def post(self, request, *args, **kwargs):
     form = BrandForm(request.POST)
     if not form.is_valid():
         kwargs['form'] = form
         return super(CBrandAdd, self).post(self, request, *args, **kwargs)
     brand = form.save()
     if 'image' in request.FILES:
         brand.image = file_put2(request.FILES['image'], brand.id, 'brand')
         brand.save()
     return redirect(reverse('control:brand'))
Пример #4
0
 def post(self, request, *args, **kwargs):
     form = CategoryForm(request.POST)
     if not form.is_valid():
         kwargs['form'] = form
         return super(CCategoryAdd, self).get(request, *args, **kwargs)
     category = form.save()
     if 'image' in request.FILES:
         category.image = file_put2(request.FILES['image'], category.id, 'category')
         category.save()
     return redirect(reverse('control:category'))
Пример #5
0
 def post(self, request, *args, **kwargs):
     categorydb = Category.objects.get(id=kwargs['categoryID'])
     form = CategoryForm(request.POST, instance=categorydb)
     if not form.is_valid():
         kwargs['form'] = form
         return super(CCategoryEdit, self).post(self, request, *args, **kwargs)
     category = form.save()
     if 'image' in request.FILES:
         if category.image!="":
             file_delete(category.image.split("/")[1])
             
         category.image = file_put2(request.FILES['image'], category.id, 'category')
         category.save()
     return redirect(reverse('control:category'))
Пример #6
0
 def post(self, request, *args, **kwargs):
     branddb = Brand.objects.get(id=kwargs['brandID'])
     form = BrandForm(request.POST, instance=branddb)
     if not form.is_valid():
         kwargs['form'] = form
         return super(CBrandEdit, self).post(self, request, *args, **kwargs)
     brand = form.save()
     if 'image' in request.FILES:
         if brand.image!="":
             file_delete(brand.image.split("/")[1])
         
         
         brand.image = file_put2(request.FILES['image'], brand.id, 'brand')
         brand.save()
     return redirect(reverse('control:brand'))