I did in this way and it works....
First i upload all the pics
def _upload_img(fpathname, path=''):
fname = os.path.split(fpathname)[1]
_dst= os.path.join( 'static/images/pics', fname)
if os.path.isfile(fpathname):
myfl = open(fpathname,'r')
cntn = myfl.read()
myfl.close()
fdst = open(_dst,'wb')
fdst.write(cntn)
fdst.close()
else:
print 'file %s not found!' % (fpathname)
return
and then I assign them to the product
if row[iind.picture]: # cell of excel import file
fname = os.path.split(row[iind.picture])[1]
_dst= os.path.join('images/pics', fname)
image = ProductImage(product=p)
image.picture =_dst
image.save()
I do not use productvariations, but i think it's not influent
Alkatron
On 06/19/2012 04:10 AM, mel bin wrote:
We have about 700 product variations. We have all the images named
based on the SKU and variation options of the products.
I am trying to write a script to import images. However, I cannot
create a ProductImage object for products:
from satchmo_utils.thumbnail.field import ImageWithThumbnailField
from product.models import Product, ProductImage
>>> from satchmo_utils.thumbnail.field import ImageWithThumbnailField
>>> from product.models import Product, ProductImage
>>> p =
KeyboardInterrupt
>>> p = Product.objects.get(sku='2833')
>>> f = open("/tmp/image_export/2833.jpg")
>>> i = ImageWithThumbnailField(f)
>>> pi = ProductImage(p.id, i)
>>> pi.save()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File
"/var/www/virtualenv/satchmo_stage/lib/python2.6/site-packages/django/db/models/base.py",
line 460, in save
self.save_base(using=using, force_insert=force_insert,
force_update=force_update)
File
"/var/www/virtualenv/satchmo_stage/lib/python2.6/site-packages/django/db/models/base.py",
line 546, in save_base
for f in meta.local_fields]
File
"/var/www/virtualenv/satchmo_stage/lib/python2.6/site-packages/django/db/models/fields/subclassing.py",
line 28, in inner
return func(*args, **kwargs)
File
"/var/www/virtualenv/satchmo_stage/lib/python2.6/site-packages/django/db/models/fields/related.py",
line 872, in get_db_prep_save
if value == '' or value == None:
File
"/var/www/virtualenv/satchmo_stage/lib/python2.6/site-packages/django/db/models/fields/__init__.py",
line 124, in __cmp__
return cmp(self.creation_counter, other.creation_counter)
AttributeError: 'str' object has no attribute 'creation_counter'
Also, if anyone have any ideas how I could have a variation display
images the following way:
- If variation has an image, display it
- Otherwise, display image of the configurable image
Thanks for any help you may offer!
--
You received this message because you are subscribed to the Google
Groups "Satchmo users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/satchmo-users/-/F9W4bIy39bcJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/satchmo-users?hl=en.
--
You received this message because you are subscribed to the Google Groups "Satchmo
users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/satchmo-users?hl=en.