def add_new_item(request): if request.method == 'POST': form = SaleItemForm(request.POST,request.FILES) if form.is_valid(): item = form.save(commit=False) item.owner = request.user.sellerprofile if 'image' in request.FILES: item.image = request.FILES['image'] item.save() if 'additional_images' in request.FILES: for image in request.FILES.getlist('additional_images'): SaleItemAdditionalImages.objects.create(image=image, sale_item=item) return redirect('shop:item', item.slug) else: print form.errors else: form = SaleItemForm() return render(request, 'shop/add_new_item.html', {'form': form})
def test_valid_saleitem_creation(self): testcat = add_cat('testcat') data = {'title': 'testtitle','condition': 'NEW', 'description': 'its legit', 'asking_price': 334334, 'payment_type':'COD', 'negotiable': True, 'expiration_date': '4/4/2015', 'category': testcat.id, 'refundable': True, 'home_delivery': True} form = SaleItemForm(data=data) print form.errors self.assertTrue(form.is_valid()) response = self.c.post(reverse('shop:add_new_item'), data) self.assertEqual(response.status_code, 302)