CSV (or any spreadsheet) Import into Satchmo

58 views
Skip to first unread message

Paul Walsh

unread,
Nov 8, 2010, 2:44:39 AM11/8/10
to Satchmo users
Hi,

I am a new Satchmo user (and a very very novice Django beginner) -
something that wasn't clear to me:

Is there a core module or an available extension to import data via
CSV? I saw the product_feeds extension module but it only seems to
deal with export.

If anyone can point me in the right direction that would be great!

Thanks,

Paul.

Alex Robbins

unread,
Nov 9, 2010, 9:11:11 AM11/9/10
to satchm...@googlegroups.com
I don't think satchmo has anything specifically for this use case.
However, you could use python's csv module.

http://docs.python.org/library/csv.html#csv.DictReader

Basically, the script would look like this:

from csv import DictReader
from product.models import Product

reader = DictReader(open('products.csv'))
for line in reader:
Product.objects.create(
#Setup the mapping between csv columns and satchmo product
attributes here
title=line['title'],
slug=line['slug_field]'
...
)

You'd probably want some error control and stuff like that, but that
is the basic idea.

Hope that helps,
Alex

> --
> You received this message because you are subscribed to the Google Groups "Satchmo users" group.
> To post to this group, send email to satchm...@googlegroups.com.
> To unsubscribe from this group, send email to satchmo-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/satchmo-users?hl=en.
>
>

Sebastian Zwack

unread,
Nov 9, 2010, 5:41:47 AM11/9/10
to Satchmo users
Hi,

I'm trying to achieve the same thing. I didn't find any information
about it in the docs so I guess this has not been implemented yet.
I will start with organizing the data from the spreadsheet and then
create new product objects and store them.

Has anyone already made this process or are there recommendations how
to add new data programmatically to satchmo in general?

Regards
Sebastian

Sebastian Zwack

unread,
Nov 10, 2010, 2:53:28 PM11/10/10
to Satchmo users
My answer below had a little delay because this was my first post
which had to be verified.

So basically I wrote a import script like you suggested. I used xlrd
(http://www.python-excel.org/) instead of the csv module as it handles
unicode out of the box. The Products and Categories show up correctly
so I guess it's working.

Paul, if you want me to send the script just let me know.

Regards
Sebastian

Alex Robbins

unread,
Nov 10, 2010, 3:07:13 PM11/10/10
to satchm...@googlegroups.com
Yeah, the unicode failing in the csv module is a pain. Every time I
use it I wonder why they didn't just make it unicode friendly. They
even have an example of the modifications to make it work with unicode
in the docs. Why didn't they just make it work from the beginning?

Anyway, good to hear it is working for you!
Alex

Christopher Wilcox

unread,
Nov 10, 2010, 3:00:14 PM11/10/10
to satchm...@googlegroups.com
Hi there,

I would also be interested in your script which imports spreadsheet data into Satchmo.

Would it be possible to share your script with me as well?

Cheers,
-Chris

Sebastian Zwack

unread,
Nov 11, 2010, 5:49:32 AM11/11/10
to Satchmo users
Ok then have a look here: http://djangosnippets.org/snippets/2255/

This is, of course, just a quick and dirty solution which needs to be
adjusted to your excel file.
I'm still working on it and will probably be adding parent/child
categories and product options.

Alex: Right, I never even tried csv when I read that. Also xlwt is
pretty cool and straight forward.

Hope that helps
Sebastian
> > satchmo-user...@googlegroups.com<satchmo-users%2Bunsubscribe@goog legroups.com>
> > .
> > > > For more options, visit this group athttp://
> > 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 satchm...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > satchmo-user...@googlegroups.com<satchmo-users%2Bunsubscribe@goog legroups.com>
> > .

Paul Walsh

unread,
Nov 11, 2010, 9:35:55 AM11/11/10
to Satchmo users
Hi Everyone,

Thanks for the help! Sebastian - thanks for putting together a script
- I'll grab it now and have a look at it.

On Nov 11, 12:49 pm, Sebastian Zwack <sebastian.zw...@googlemail.com>
wrote:

Jeff Cook

unread,
Nov 18, 2010, 2:18:15 PM11/18/10
to satchm...@googlegroups.com
When I try to run a modified version of the script included a bit
earlier, I get complaints about DJANGO_SETTINGS not being found. If I
update the env to include something like (from memory, don't have the
machine/errors in front of me right now)
DJANGO_SETTINGS=satchmo_store.settings.store_settings, I get
complaints that the settings module does not contain some important
satchmo thing. Anyone know the way around this? Let me know if these
errors are too vague and I can include the real messages, I am just in
a hurry and want to ping and see if anyone knows an easy fix for these
kinds of errors.

Thanks in advance.

From
Jeff

> To unsubscribe from this group, send email to satchmo-user...@googlegroups.com.

Alex Robbins

unread,
Nov 18, 2010, 4:47:33 PM11/18/10
to satchm...@googlegroups.com
If you call stuff from inside ./manage.py shell, then the settings are
already loaded. Maybe just import the function from the path and run
it that way.

For example:

load_products.py
#####
def run():
do_all_the_loading()
....
#####

Then at the terminal say:
./manage.py shell
from load_products import run
run()

That should clear up the settings issues.

Alex

cool-koala

unread,
Nov 23, 2010, 1:54:51 AM11/23/10
to Satchmo users
Thanks to Sebastian for the Product Importer script. I have modified
it somewhat and it works well. The only issue still remaining for me
is the actual saving of the ProductImage. Simply entering the filepath
to the image on the xls file does not save the image. I have given
this alot of thought and I am still a novice with Django/Python so I
was wondering if anyone have any suggestions? Much appreciated thank
you.

Sebastian Zwack

unread,
Nov 23, 2010, 4:19:33 AM11/23/10
to Satchmo users
Good to hear that this could be of some help.
In the meantime I added some more things like hierarchical categories
and product variations. Have a look at the updated script on django
snippets.
http://djangosnippets.org/snippets/2255/

What's the exact issue with the product image? When you're using
django static file serving then moving the images to static/images
(which seems to be the image upload path) works for me. Apache could
be configured likewise.

Jacques Nel

unread,
Nov 26, 2010, 12:00:01 AM11/26/10
to satchm...@googlegroups.com
Hi Sebastian,

My previous comment was not entirely accurate as I have been mistaken in the thought that simply putting an image path to the picture would not read the image. I have tried your script again and thank you for the brilliant job you have done. 

All is well in the land of Satchmo again :D




Sebastian Zwack

unread,
Nov 26, 2010, 11:08:39 AM11/26/10
to Satchmo users
Great that it's working for you now Jacques.
I also fixed a bug in the script when using hierarchical categories.

Jeff Cook

unread,
Dec 2, 2010, 2:34:37 AM12/2/10
to satchm...@googlegroups.com
So I'm using this script to add a lot of products. I'm trying to use
the product variation features. I've got it mostly working, except:
* I want to do an absolute price override for the different options,
not just a price delta. I've set the price for the productvariation by
hand, but it doesn't change when I select the other option.
* Every configurable product says, "Sorry, we don't have any of that
combination available." What do I need to set? I've been setting the
items_in_stock thing on the product variation as well.

What do I need to set to make these problems go away?

Thanks in advance, and thanks for this script, it's been a very
helpful starting point. :)

From
Jeff

Sebastian Zwack

unread,
Dec 2, 2010, 5:23:59 AM12/2/10
to Satchmo users
I'm using absolute prices on variations too and it's working for me.
Did you set the root ConfigurableProduct to zero?
Not sure if this is necessary but that's what I have.

I encountered the out of stock msg myself and finally looked into it.
It's a refreshing problem. After all products have been created you
need to call ProductPriceLookup.objects.rebuild_all(). I added it to
the script.


On Dec 2, 8:34 am, Jeff Cook <j...@deserettechnology.com> wrote:
> So I'm using this script to add a lot of products. I'm trying to use
> the product variation features. I've got it mostly working, except:
> * I want to do an absolute price override for the different options,
> not just a price delta. I've set the price for the productvariation by
> hand, but it doesn't change when I select the other option.
> * Every configurable product says, "Sorry, we don't have any of that
> combination available." What do I need to set? I've been setting the
> items_in_stock thing on the product variation as well.
>
> What do I need to set to make these problems go away?
>
> Thanks in advance, and thanks for this script, it's been a very
> helpful starting point. :)
>
> From
> Jeff
>
> On Fri, Nov 26, 2010 at 9:08 AM, Sebastian Zwack
>

Jeff Cook

unread,
Dec 4, 2010, 1:41:45 AM12/4/10
to satchm...@googlegroups.com
I resolved the pricing problem by setting the script to create things
correctly, where a ConfigurableProduct stands alone and each variation
of the product is an individual ProductVariation. It looks like you
didn't have this issue because your spreadsheet was created for
variations/configurability. Mine wasn't. It took a while to figure out
that CPs should be standalone without a variation on the same product.
Each CP should be a master product, and then individual variations
standalone. In this setup, it works fine. I am not zeroing the price.

Thanks for the ProductPriceLookup rebuild line, that does resolve that issue.

Now I have one more problem, and I could solve it myself by copying
files manually, but such a way is slow and I'd like to know what you
all think is the best way to handle this. Right now, when an image is
set, it is moved out of its directory into Satchmo's directory. I
don't want the image to be moved -- I want it to be copied. Does
anyone have a recommendation for the correct way to tell Satchmo to
copy, not move, the product's image? I could copy the file in the
script but as mentioned above, I'd like to know if there is something
simple like a parameter I can pass that will just the copy the image
from its place to Satchmo instead of moving it.

Thanks for all the help so far. :)

From
Jeff

Sebastian Zwack

unread,
Dec 10, 2010, 5:31:01 AM12/10/10
to Satchmo users
Right I had a row for the ConfigurableProduct and the variations each
in my spreadsheet.

I'm not sure what your problem with the image is exactly. The import
itself just sets the path and you need to move the images there for
yourself. Or do you have django running when doing the import? Then I
guess satchmo is doing the same thing as if you add an image using the
admin interface.

Sebastian

On Dec 4, 7:41 am, Jeff Cook <j...@deserettechnology.com> wrote:
> I resolved the pricing problem by setting the script to create things
> correctly, where a ConfigurableProduct stands alone and each variation
> of the product is an individual ProductVariation. It looks like you
> didn't have this issue because your spreadsheet was created for
> variations/configurability. Mine wasn't. It took a while to figure out
> that CPs should be standalone without a variation on the same product.
> Each CP should be a master product, and then individual variations
> standalone. In this setup, it works fine. I am not zeroing the price.
>
> Thanks for the ProductPriceLookup rebuild line, that does resolve that issue.
>
> Now I have one more problem, and I could solve it myself by copying
> files manually, but such a way is slow and I'd like to know what you
> all think is the best way to handle this. Right now, when an image is
> set, it is moved out of its directory into Satchmo's directory. I
> don't want the image to be moved -- I want it to be copied. Does
> anyone have a recommendation for the correct way to tell Satchmo to
> copy, not move, the product's image? I could copy the file in the
> script but as mentioned above, I'd like to know if there is something
> simple like a parameter I can pass that will just the copy the image
> from its place to Satchmo instead of moving it.
>
> Thanks for all the help so far. :)
>
> From
> Jeff
>
> On Thu, Dec 2, 2010 at 3:23 AM, Sebastian Zwack
>

Jeff Cook

unread,
Dec 17, 2010, 9:43:47 PM12/17/10
to satchm...@googlegroups.com
Just found a big problem with this if you want to discount by
category. The script removes ProductVariations from their respective
categories because if it doesn't, they will display in the list with
the CPs. However, you can't discount a category if things are like
that, because people can only buy individual products and not
ConfigurableProducts. Since individual products aren't part of the
category, the discount cannot be applied to the products that people
actually buy.

Is there a field that makes a product not display on a category list,
but still be purchaseable, etc.? If so, I need to set it ASAP. Thanks.

Sebastian Zwack

unread,
Dec 18, 2010, 5:47:49 AM12/18/10
to Satchmo users
Right, when I encountered the ProductVariation showing up I just
removed the category from it.
I can't test it from here but what does it look like when you
configure a CP and PV through the admin?

For a quick solution you could probably add the categories to the PVs
and filter them out in the template rendering.

davidl

unread,
Jan 14, 2011, 2:46:02 AM1/14/11
to Satchmo users
Hi Sebastian,

I'm a newbie when it comes to django and satchmo. Just installed
Satchmo and trying to make it work, so I won't have to go back to
Magento for my company's ecommerce site. Seems like this snippet
http://djangosnippets.org/snippets/2255/ will save me a lot of time.

However, I'm little lost on how to make this work with Satchmo. Where
would I be placing this code snippet and make it run?

David

On Dec 18 2010, 2:47 am, Sebastian Zwack

Chris Moffitt

unread,
Jan 14, 2011, 9:31:57 AM1/14/11
to satchm...@googlegroups.com
I haven't personally used this script but it looks like it's a standalone python file. I would recommend saving this in your project directory (same directory as manage.py) and try running is with python  new-script-name.py

Hope that helps.

-Chris

Sebastian Zwack

unread,
Jan 14, 2011, 9:35:28 AM1/14/11
to Satchmo users
Right, it's standalone.
It's actually described in the comment in line 6. Place it in a folder
just below the project directory.

Sebastian

On Jan 14, 8:46 am, davidl <davidle...@gmail.com> wrote:
> Hi Sebastian,
>
> I'm a newbie when it comes to django and satchmo. Just installed
> Satchmo and trying to make it work, so I won't have to go back to
> Magento for my company's ecommerce site. Seems like this snippethttp://djangosnippets.org/snippets/2255/will save me a lot of time.

Patrick Rynhart

unread,
Feb 5, 2011, 9:34:19 PM2/5/11
to Satchmo users
I hear you! I am also looking to migrate off Magento primarily due
to preformance reasons. Satchmo seems lean & mean and IMHO handles
customisation in a *much* cleaner fashion.

Cheers,

Patrick

On Jan 14, 8:46 pm, davidl <davidle...@gmail.com> wrote:
> ...so I won't have to go back to
Reply all
Reply to author
Forward
0 new messages