Problem: I have a database with 3 foreign keys, every day i have to collect the user input with the following rules;
if there is already data present for today's date in db, then retrieve and display the data. the data will result in multiple rows, but each row is uniquely queried based on the 3 foreign keys (product, branch, merge_version,) and date_created (auto_add=True)
if the query did not return anything, create a object with class instance and display empty rows
if the user click one single submit button, the data should be updated in the database with the following rules;
- For each row submitted, validate if there is already an existing row present in database, if there is a row, update the row, else create a new row
I tried with creating multiple form instance in a for loop, for each product, and send the dictionary to template page, and it displays the rows without any issues.
When i click submit, only the last row data is saved, since request.POST returns the following output;
QueryDict: {u'build_date': [u'2013-10-11', u'2013-10-11', u'2013-10-11', u'2013-10-11', u'2013-10-11', u'2013-10-11', u'2013-10-11', u'
2013-10-11'], u'cln': [u'5555', u'2222', u'2222', u'2222', u'2222', u'2222', u'2222', u'090909'], u'logs': [u'no logs', u'no logs', u'no logs', u'no logs', u'no logs', u'n
o logs', u'no logs', u'no logs'], u'rpmt_status': [u'R', u'R', u'R', u'R', u'R', u'R', u'R', u'R'], u'rpmt_result': [u'F', u'F', u'F', u'F', u'F', u'F', u'F', u'F'], u'com
ments': [u'hghjg', u'hghjg', u'hghjg', u'hghjg', u'hghjg', u'hghjg', u'hghjg', u'hghjg'], u'cbs_other_bugs': [u'666', u'666', u'666', u'666', u'666', u'666', u'666', u'666
'], u'build_num': [u'12345', u'4444', u'8888', u'8888', u'8888', u'8888', u'8888', u'080808'], u'cbs_merge_blocker': [u'76767', u'76767', u'76767', u'76767', u'76767', u'7
6767', u'76767', u'76767'], u'csrfmiddlewaretoken': [u'8sNCLiUu23tvqLe1QHdJp1c5sQJmhevw'], u'cbs_waived': [u'89898', u'89898', u'89898', u'89898', u'89898', u'89898', u'89
898', u'89898']}
if i have individual submit button for each row i get the below request.POST
QueryDict: {u'build_date': [u'2013-10-11'], u'cln': [u'23423'], u'logs': [u'no logs'], u'rpmt_status': [u'R'], u'rpmt_result': [u'F'], u'comments': [u'hghjg'], u'cbs_other_bugs': [u'666'], u'build_num': [u'12345'], u'cbs_merge_blocker': [u'76767'], u'csrfmiddlewaretoken': [u'8sNCLiUu23tvqLe1QHdJp1c5sQJmhevw'], u'cbs_waived': [u'89898']}
But i want to save the the entire database with one submit button. Please tell me where i am making mistake? or is there a best way to handle this situation other than using ModelForm?