Of course, you don't have poppulated payment_form ? Only initializated,

payment_form = AddPaymentForm()

If I'm not helping you, please attach more code


good luck!


Missatge de chevalier <chevalie...@gmail.com> del dia ds., 24 d’ag. 2019 a
les 17:37:

> 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 django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5a7edbc8-7d20-42aa-8d8e-e8c122026a12%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/5a7edbc8-7d20-42aa-8d8e-e8c122026a12%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK-JoTTdn6-iDutuy5u2UcDf%3DoRQYme93dLmBxOiSOWh5zb_bQ%40mail.gmail.com.

Reply via email to