def post(self, request): if request.POST['id']: item = Item.objects.get(id=request.POST["id"]) else: item = Item() item.name = request.POST["name"] item.description = request.POST["description"] item.company = request.user.company item.save() return JsonRepsonse({"Upload": True, "id":item.id})
def addItem(request, cat_id): if request.method == 'POST': form = ItemForm(request.POST) if form.is_valid(): cd = form.cleaned_data newItem = Item() newItem.name = cd.get('name') newItem.description = cd.get('description') newItem.quantity = cd.get('quantity') currentCat = request.POST.get("category") newItem.category = get_object_or_404(Category, id=currentCat) newItem.save() items = Item.objects.all().filter(category=currentCat) context = {'items': items,} if request.is_ajax(): return render_to_response('inventory/getList.html', context, context_instance=RequestContext(request)) else: return HttpResponseRedirect(reverse('inventory:list', args=(cat_id,))) message = "Oops, it broke! You should enter in something valid." form = CategoryForm() categories = Category.objects.all() context = {'message': message, 'form': form, 'categories': categories, } return render_to_response('inventory/index.html', context, context_instance=RequestContext(request))
def addItem(request, cat_id): if request.method == 'POST': form = ItemForm(request.POST) if form.is_valid(): cd = form.cleaned_data newItem = Item() newItem.name = cd.get('name') newItem.description = cd.get('description') newItem.quantity = cd.get('quantity') currentCat = request.POST.get("category") newItem.category = get_object_or_404(Category, id=currentCat) newItem.save() items = Item.objects.all().filter(category=currentCat) context = { 'items': items, } if request.is_ajax(): return render_to_response( 'inventory/getList.html', context, context_instance=RequestContext(request)) else: return HttpResponseRedirect( reverse('inventory:list', args=(cat_id, ))) message = "Oops, it broke! You should enter in something valid." form = CategoryForm() categories = Category.objects.all() context = { 'message': message, 'form': form, 'categories': categories, } return render_to_response('inventory/index.html', context, context_instance=RequestContext(request))