Re: Bulk-creating two ForeignKey linked models - id field for relationship isn't set properly?
Hi,
-- In the source file (JSON) - I have a list of Products dictionaries.
The images are one of the elements in that dictionary - hence, the link between them is that images is a child of Product.
Hence, when I loop through to create Product, I can create the images and link it there.
At the end, the ProductImage objects all have a valid Product field, but no valid Product_id field - perhaps I can create all the Products/ProductImages, do a bulk_create() on the Products, then do a lookup for each ProductImage for that Product and assign a valid product_id?
However, not sure whether doing that extra lookup is going to be any better than just iterating through and doing a save() each round and avoiding bulk_create() altogether.
Cheers,
Victor
On Tuesday, 20 August 2013 22:51:57 UTC+10, Daniel Roseman wrote:
On Tuesday, 20 August 2013 22:51:57 UTC+10, Daniel Roseman wrote:
On Tuesday, 20 August 2013 12:10:34 UTC+1, Victor Hooi wrote:Hi,1. Hmm, in that case, using bulk_create may not work - I'm currently relying on generating the full lists of Products and ProductImages, then saving in a batch at the end.So I need to loop through and call .save() individually on each Product, then the corresponding ProductImages, before moving onto the next Product().Are there any workarounds for this, or any way I could still leverage on bulk_create()?Can you bulk save the Products first, then assign them to the ProductImages and bulk save those?--DR.
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home