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 at the same time want to update the Sim model as
well.
I am 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/f4b942d8-fc4e-48ed-9f1d-d8b9f0f75dc2%40googlegroups.com.