I have a problem, I want to get all the data from the list
, so I want to loop through each data in the selected item and insert it into the database,
Currently when I print ['[object Object]', '[object Object]']
, it returns data like this,
How to insert these data one by one? Or just print them one by one?
I have this list which is selected_items I loop the data and then pass it to ajax
1 2 3 4 5 6 7 8 |
|
When the console selected_items is like this
So now I want to pass these lists to django using ajax
1 2 3 4 5 6 7 8 |
|
views.py
1 2 |
|
It prints out like this
1 |
|
Update codeHow to loop data? This is what I tried but it doesn't reflect the data at all
1 |
|
view.py
1 2 3 4 |
|
**How to print or insert into database?
P粉6804879672024-04-04 14:29:06
When you do selected_items.join(',')
, you are getting the __str__# of
{'stock_id': 5, 'quantity': 15} ## (or equivalent js), which happens to be
[object Object ]
Javascript
1 2 3 4 5 6 7 8 |
|
1 2 3 4 5 6 7 8 9 10 |
|
1 2 3 4 5 6 7 |
|
but! If you know that you are going to create each project, I recommend using bulk_create
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
The working principles of these are the same!
(It is very convenient to create filters dynamically ;))
1 2 3 4 5 6 7 8 9 10 11 12 |
|