> left: bulk upload. I've thought of using xls (microsoft
> office's excel files) to make it easy on the client, because
> teaching them xml or yaml isn't the big deal. After thinking
> about it, finding a xls parser module for python might not be
> the problem, 

I second the idea of using a plain-text interchange format, 
whether CSV as David suggested, or (my preferred) tab-delimited 
format.  I dislike CSV because it takes extra overhead to 
synchronize the flavors of them (how are quotes quoted?  are 
values quoted? etc).  I find TAB format just less messy.

> but how could I take on product images? How can I
> bulk upload those? Ok, I can upload a tar or zip file and have
> it unpacked automatically, but how do I automagically assign
> the images with the product, having in mind that some might
> have 5 pics and others might have 2 or none.

Your idea of uploading a zip/tar archive is a good one.  One 
would need to go with naming conventions.  Images could be named 
of the format <part_number>_<id>.[jpg|gif] and then any 
corresponding items could be added to your ProductImages table. 
This assumes you have a <part_number> column in your upload file.

You might want to report on items in the image-archive that don't 
have a corresponding item in the upload file (or aren't already 
in the data...might be easier).

To augment Adam's suggestion, a lot of the code can be made 
shorter and more readable using Python's tuple-assignment, so 
rather than having hard-coded indicies such as "product.slug = 
raw_data[6]", you can do something like

  (in_id,
   manufacturer,
   vendor,
   dealer_price,
   dealer_price_updated,
   model,
   slug,
   description,
   package_contents,
   ...
   ) = raw_data

You can then use each of these parts for later assignment, or 
even directly assign them like

  (in_id,
   manufacturer,
   ...
   product.model,
   product.slug,
   product.description,
   ... ) = raw_data

This does assume a fixed column order, which would require some 
tweaks if the columns could be in an arbitrary order.  However, a 
little dictionary trickery can solve that.  I usually do this via

REQUIRED_COLUMNS = [
   'manufacturer',
   'slug',
   ...
   ]
for row_num, row in file(filename):
   row = row.rstrip('\n').split(DELIM)
   if row_num == 0:
     header_to_column = dict([
       (n, i) for (i,n)
       in enumerate(row)])
     header_set = set([h.lower() for h in row])
     for header in REQUIRED_COLUMNS:
       assert header in header_set, 'Missing column %s' % header
     continue
   # use header_to_column to map the desired column name
   # to its offset/index


-tim





--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to