Hello all.
I need to import in one table data keeping original id's.
I know that I have to drop the table first, but when I want to import the
CSVfile web2py say me that " 'DAL' object
has no attribute 'products'
I've tried to follow these instructions:
http://web2py.com/books/default/chapter/30/06/lastrazione-del-database?search=import_from_csv_file
And also here:
https://groups.google.com/forum/#!searchin/web2py/id_map{}/web2py/tURuX_Yyr2k/tzOzB4mGVkQJ
In my csv file I have:
products.id,products.code,products.description
407,040525,DA 9-24
408,040586,DR 14-37
Here is my db:
db.define_table('products',
Field('code', unique=True),
Field('description'),,
format='%(code)s')
db.define_table('csv_products_files',
Field('csv_file', 'upload', requires = IS_NOT_EMPTY()),
auth.signature)
My controller:
def import_products():
form=SQLFORM(db.csv_products_files)
if form.process().accepted:
response.flash = 'Form accepted'
db.products.drop()
db.products.import_from_csv_file(open(form.vars.csv_file, 'r',
id_map={}))
elif form.errors:
response.flash = 'Form has errors'
return locals()
Someone knows how I can resolve it ?
Thanks.
--
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/groups/opt_out.