Tuesday, July 1, 2014

how to saven models dynamically inputted by user in form

this is my code-
def final(request, name):
    if request.method == 'POST':
        form = ConfirmForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            quote_item = request.POST['quote_item']
            quote_qty = request.POST['quote_qty']
            #obj = PurchasedItem.objects.create(item__name=quote_item, qty=quote_qty,price=quote_price)
            obj = PurchasedItem(item__name=quote_item__name, qty=quote_qty)
            obj.save()
            purchase_order = PurchaseOrder.objects.get(pk=name)
            item = PurchasedItem.objects.filter(purchase_order_id=name).values_list('item__name', 'qty', 'price')
            total_cost = PurchasedItem.objects.filter(purchase_order_id=name).aggregate(Sum('price')).get('price__sum', 0.00)
            return render(request, 'bills/bills.html', {'purchase_order' : purchase_order,
                 'item' : item, 'total_cost' : total_cost, 'form':form })
     
    else:
        form = ConfirmForm()
    return render(request,'bills/bills.html')



in this code obj.save() method is not working . Kindly help.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c2c02b8c-0b14-4072-a97c-a4e452504afb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment