def sale_add(request): if request.method == 'POST': form = SaleForm(request.POST) p_sn = generate_sn(prefix = 'SO') if form.is_valid(): p = form.save(commit=False) p.sn = p_sn p.save() serializer = JSONSimpleSerializer() return HttpResponse(serializer.serialize([p,], use_natural_foreign_keys=True)) else: print form.errors else: form = SaleForm() return render_to_response('modal/main_form.html',{'action':'Add', 'module':module, 'form': form},context_instance=RequestContext(request))
def sale_update(request): if request.method == 'POST': postdata = request.POST.copy() try: p = SaleOrder.objects.get(sn=postdata.pop('sn')[0]) except SaleOrder.DoesNotExist: raise Http404(module + ' not found') form = SaleForm(postdata, instance=p) print form.errors if form.is_valid(): p_saved = form.save() # updateSalePrice(p_saved.sn) p.updatePrice() serializer = JSONSimpleSerializer() return HttpResponse(serializer.serialize([p,],use_natural_foreign_keys=True)) else: return HttpResponse('Invalid request.')