On Wednesday, October 14, 2015 at 11:03:02 AM UTC-7, TheFltube wrote:
>
> Hi folks, glad to join this group
>
> I tried to import in Web2Py the attached CSV file ( no sensible data, just 
> fake info for training ;), after having created the corresponding db.py
>
> It works but only IDs are created for the correct number of rows ( held in 
> CSV ) but no field is actually loaded, they're all empty
>
> If i try to access SqlLite db and import the CSV into the already created 
> table ( by db.py ) , it works like a charm and data are correctly visible 
> and accessible via controllers/views
>
> Sorry ( and apologize ) if the post has already been threaded in another 
> section
>


I think we're going to need to see what your code looks like in order to 
comment sensibly.  How are you getting the file, copied by hand by the 
Admin user, or uploading it through a controller?  How are you importing 
the file once you have it?

I hadn't done this before, as the appadmin console had always done enough 
for me.  But you inspired me to write a controller and whip up a model, and 
give it a shot.  First thing I found out was how much I had forgotten about 
queries since the last time I worked on one.  Then I used SQLFORM, rather 
like the Image Blog in Chapter 3
<URL:http://web2py.com/books/default/chapter/29/03/overview#An-image-blog>
Because of SQLFORM, I created a table for the forms, with a "something" 
field (string) and a "myfile" field (upload).  Then I created the table I 
wanted to import to.  The accepted form had the filename in 
form.var.myfile, so I just plugged that into the csv import call (hardwired 
the directory portion as a shortcut)..

It was pretty easy, although I did fumble around a bit trying to select an 
ID from request.vars, but that was an unnecessary side trip.  And while the 
upload table is handy for debugging, I will probably put a truncate on it 
because it really is just temporary information.

Ah, I just took a look at your actual csv file.  One difference is that I 
have an id column as a result of "always having done it that way" for 
appadmin, so I cloned an input file and stripped out the id column.  Still 
worked fine.

Dave
/dps

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to