Nisha Patel
Problem
I am trying to combine two models into one form. However I cannot save the form as it is not an instance of the models. What I'm after is a way to access the models as instances and then save them. I am using crispy forms, I have described what I have tried at the bottom of the post, I have no idea why this is not working so as always any help is appreciated.
This is my model.py file:
forms.py:
and my view.py
I have tried:
booking_instance = customer_booking_form.cleaned_data['booking_form'].save()
However, this is not recognizing the fields 'customer_form' or 'booking_form'
Solution
Instantiate both forms in your view, just add a prefix argument to at least one of them.
The prefix will let Django give each form a unique namespace. So, the field name values will have the specified prefix for that ModelForm, i.e., customer-first_name, booking-booking_time, etc.
Answered by: >McPherson
Credit: >StackOverflow
Blog links:
>How to show encrypted user id in URL in Laravel?
>How to fix Laravel LiveWire listener?
>Run Laravel Project to Active Local Server