I have two related models (Sim and Payment - A Sim can have many Payment). 
On searching of Sim (by ID ) i want its detail to be populated in a form 
(*which 
i am able to*). But using the same form i want to save the details of 
Payment model as well and want to update the Sim model as well. 

I am only able to populate only Sim form using the id but the 
AddPaymentForm is not populating.


def updatePayment(request, id):
>     sim  = get_object_or_404(Sim, pk=id)
>     payment = AddPaymentForm()
>     sim_form = UpdatePayment(request.POST, instance=sim)
>     if request.method == "POST":
>         # sim_form = UpdatePayment(request.POST, instance=payment)
>         payment_form = AddPaymentForm()
>         try:
>             if payment_form.is_valid():
>                 payment_form.save()
>                 sim_form.save()
>                 messages.success(request, ("Payment has been updated"))
>             else:
>                 messages.warning(request, ("Data in fields is incorrect, 
> please try again"))
>         except Exception as e:
>             messages.warning(request, ("Error: {}".format(e)))
>     else:
>         form = UpdatePayment(instance=sim)
>         payment = AddPaymentForm()
>     context = {'payment': payment, 'form': form,}
>     return render(request, 'payment/updatePayment.html', context) 
>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5a7edbc8-7d20-42aa-8d8e-e8c122026a12%40googlegroups.com.

Reply via email to