Sunday, June 2, 2013

Re: how to import excel file into django models?

Just a small clarification - xlrd runs on both Windows and Linux and would be the recommended way to go here.

Otherwise I agree with Vernon - create a base xlrd_reader class, to handle generic reading and data checking, and then have model-specific routines that handle assignment of data to specific fields.  There is a ton of example code for xlrd on the web, and some with examples for Django.  My code works with forms that let the user specify which columns are being used for what, rather than a command-line approach.  How you handle this aspect depends on your use case...

Derek

On Sunday, 2 June 2013 21:44:53 UTC+2, Vernon D. Cole wrote:
I have used two methods -- one works only on Windows, the other is cross platform -- and you have said nothing about your application so it is hard to advise...

If you know Windows and SQL -- then use adobapi and open the spreadsheet as a table (see examples at http://sourceforge.net/projects/adodbapi) and read it using SQL SELECT commands.

If you are on Linux, then xlrd is your friend.  (Find it on pypi or http://www.python-excel.org/)  In my case, the spreadsheet was large, and the columns moved around from time to time, so I wrote a mini-ORM (xlrd_helper) to allow me to refer to the spreadsheet columns by name, rather than by number, and handle the idiosyncrasies of my application.  I have been working on this for several months, but my work is too application specific to publish.  (You probably do not need to do automatic spelling correction for the names of Nigerian villages.)  The python code which does the import is implemented as a set of manage.py command scripts.
--
Vernon Cole

On Saturday, June 1, 2013 3:21:33 AM UTC-6, Ali hallaji wrote:

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate