Saving a form collection with related models #143
Unanswered
omarcoming
asked this question in
Q&A
Replies: 1 comment 1 reply
-
without going too much into your details (didn't try to get your code up and running), did you have a look at the example 'CompaniesCollection'. For me, your use-case looks very similar to that example. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm having trouble getting my form collection to save. I have 3 models I'm working with: Contacts, Line, and Payment where Line has a foreign key to Payment and Payment has a foreign key to Contacts. LineCollection is implemented with siblings to add additional rows. I've created a form collection for Line (contains LineForm) and Payment (contains LineCollection and PaymentForm). InvoiceCollection contains PaymentCollection and ContactCollection. However in order to simplify the problem and isolate the issue I didn't implement Contacts yet. I've been following the documentation, studying the test app, and searching through github but I am stumped.
This is the error I get:
Unprocessable Entity: /invoice/add/ [30/May/2024 19:36:24] "POST /invoice/add/ HTTP/1.1" 422 126
Exploring this further I see:
{'lines': {'__all__': ['Form data is missing.']}, 'payment': {'__all__': ['Form data is missing.']}}
First thing I can't figure out is the data variable in retrieve_instance function in my parent collection (PaymentCollection), is a list that only contains the child collection (LineCollection). So I changed the function so that I'm setting data to self.data.get('payment') and I'm able to return an instance of Payment.
The other thing I noticed is the payment and id fields are empty strings. If I understand correctly, retrieve_instance is meant to point payment to a Payment object. Does the id field only update if you add additional siblings?
Since this didn't work I tried removing ContactCollection from InvoiceCollection but I still get the same error.
I will include the relevant code.
Beta Was this translation helpful? Give feedback.
All reactions