Example #1
0
def saleItem_update(request):
  if request.method == 'POST':
    postdata = request.POST.copy()
    p_pk = postdata.pop('order')[0]
    sn = postdata.pop('sn')[0]
    p = SaleOrder.objects.get(pk=p_pk)
    pi = SaleItem.objects.get(order=p, sn=sn)
    form = SaleItemForm(postdata, instance=pi)
    if form.is_valid():
      pi_saved = form.save()
      serializer = JSONSimpleSerializer()
      return HttpResponse(serializer.serialize([pi_saved,], use_natural_foreign_keys=True))
  else:
    pass
Example #2
0
def saleItem_add(request):
  if request.method == 'POST':
    postdata = request.POST.copy()
    p_sn = postdata.pop('itemLinkSn')[0]
    sn = postdata.pop('sn')[0]
    form = SaleItemForm(postdata)
    if form.is_valid():
      pi = form.save(commit=False)
      p = SaleOrder.objects.get(sn=p_sn)
      pi.order = p
      pi.sn = SaleItem.objects.filter(order = p).count() + 1
      pi.save()
      serializer = JSONSimpleSerializer()
      return HttpResponse(serializer.serialize([pi,], use_natural_foreign_keys=True))
    else:
      print form.errors
  else:
    return HttpResponse("Invalid request.")