Help with My Inventory Import Script

Skip to first unread message

Tim Walzer

Jul 1, 2013, 2:28:46 PM7/1/13
I have put together an import script to load inventory from a CSV.  I thought everything was working fine until I took a look at the images that were imported.

For reference the image section of my script looks like this:
file = <full path to image> # /home/ubuntu/web/<uri>/store/static/images/<file_name>.jpg 
image = ProductImage(product=product)
image.picture = file 

After importing the products, I noticed that in the admin, the path to to the image was: "/media/home/ubuntu/web/<uri>/store/static/images/productimage-picture-<file name>.jpg"

In the filesystem I realized that the images were now at "/home/ubuntu/web/<uri>/store/static/home/ubuntu/web/<uri>/store/static/images/productimage-picture-<file name>.jpg"

After digging into this I realized that with 'RENAME_IMAGES' set to true, the images were not only being renamed, but because of an issue with relative vs absolute paths, they were being moved as well.

So, not wanting my images moved I set 'RENAME_IMAGES' to false and ran the script again.

Now in the admin the path to the images is: "/home/ubuntu/web/<uri>/store/static/images/productimage-picture-<file name>.jpg"  Note that the /media has been dropped from the beginning.
However in this case the image does not show in the admin section because the server doesn't know how to serve that path.  Fortunately Sorl Thumbnail correctly creates and caches the thumbnail so in the store the image is displayed correctly.

So, my question is, what is the likely cause of this issue and how do I get the path in the admin section to be "/media/images/<file name>.jpg"?

Williams Mendez Taveras

Feb 2, 2014, 6:29:10 AM2/2/14

This is what works for me:

ProductImage.objects.get_or_create(product=product, picture=('images/%s' % image), caption=product_name)
Reply all
Reply to author
0 new messages