Script to import product images

42 views
Skip to first unread message

bel

unread,
Jun 18, 2012, 10:27:31 PM6/18/12
to satchmo-d...@googlegroups.com
[I thought I posted this on Satchmo users, went back to delete it and post here but cannot find my posting]

We have over 700 product variations. We are trying to import product images. Writing a script to do this but having issues when trying to figure out how to accomplish this:

>>> from satchmo_utils.thumbnail.field import ImageWithThumbnailField
>>> from product.models import Product, ProductImage
>>> p =
KeyboardInterrupt
>>> p = Product.objects.get(sku='2833')
>>> f = open("/tmp/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_staging/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_staging/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_staging/lib/python2.6/site-packages/django/db/models/fields/subclassing.py", line 28, in inner
    return func(*args, **kwargs)
  File "/var/www/virtualenv/satchmo_staging/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_staging/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'

How am I suppose to do this? Anyone can help?

Gunnar Scherf

unread,
Jun 19, 2012, 3:36:57 AM6/19/12
to satchmo-d...@googlegroups.com
Hi,
I use something like this to import images:
   
    if os.path.exists(image_path_name):           
            try:               
                f = open(image_path_name, 'rb')
                picture = File(f)
                image = ProductImage(product=product)
                image.save()
                image.picture.save(image_file_name, picture, save=True)
            except IOError, e:
                print e

With best regards
Gunnar

2012/6/19 bel <bel...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Satchmo developers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/satchmo-developers/-/XxNEOdxkfoQJ.
To post to this group, send email to satchmo-d...@googlegroups.com.
To unsubscribe from this group, send email to satchmo-develop...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/satchmo-developers?hl=en.

bel

unread,
Jun 20, 2012, 6:30:18 PM6/20/12
to satchmo-d...@googlegroups.com
Thank you. Working great!
2012/6/19 bel <bel...@gmail.com>
To post to this group, send email to satchmo-developers@googlegroups.com.
To unsubscribe from this group, send email to satchmo-developers+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages