Esempio n. 1
0
def purchaseItem_update(request):
  if request.method == 'POST':
    postdata = request.POST.copy()
    p_pk = postdata.pop('order')[0]
    sn = postdata.pop('sn')[0]
    p = PurchaseOrder.objects.get(pk=p_pk)
    pi = Purchase_Item.objects.get(order=p, sn=sn)
    form = Purchase_ItemForm(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
Esempio n. 2
0
def purchaseItem_add(request):
  if request.method == 'POST':
    postdata = request.POST.copy()
    p_sn = postdata.pop('itemLinkSn')[0]
    sn = postdata.pop('sn')[0]
    form = Purchase_ItemForm(postdata)
    if form.is_valid():
      pi = form.save(commit=False)
      p = PurchaseOrder.objects.get(sn=p_sn)
      pi.order = p
      pi.sn = Purchase_Item.objects.filter(order = p).count() + 1
      pi.save()
      serializer = JSONSimpleSerializer()
      return HttpResponse(serializer.serialize([pi,], use_natural_foreign_keys=True))
  else:
    return HttpResponse("Invalid request.")