How to insert data using .csv or .xml file

54 views
Skip to first unread message

Sai Harsh Tondomker

unread,
Aug 3, 2015, 1:28:06 AM8/3/15
to web2py-users
Here is my db.py 
db.define_table("Questions",
  Field('quesno','integer',notnull=True,unique=True),
  Field('question', 'text'),
  Field('qupload','upload',label='Upload Image'),
  Field('optionA', 'string'),
  Field('optionB', 'string'),
  Field('optionC', 'string'),
  Field('optionD', 'string'),
  Field('True1', 'string'),
  Field('False0', 'string'),
  Field('answer', 'string'),
  )

Were and how to right the code to store data from .csv or .xml in data base I am struggling for it please help me to solve the problem. 

Selman Kocael

unread,
Aug 3, 2015, 1:37:51 AM8/3/15
to web...@googlegroups.com
simple way:

browse your csv file and click import csv button. 


if an error displayed, you must edit yoru csv file. 

--
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+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Selman Kocael
İsabet Yayınları

Sai Harsh Tondomker

unread,
Aug 3, 2015, 1:56:03 AM8/3/15
to web...@googlegroups.com
No need to write code to store in db. 

You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/d38qTLOsOnE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

Selman Kocael

unread,
Aug 3, 2015, 2:46:27 AM8/3/15
to web...@googlegroups.com
you can also import csv file with code. but i have not try it.

Sai Harsh Tondomker

unread,
Aug 3, 2015, 3:32:47 AM8/3/15
to web...@googlegroups.com
How it will store the data. We need to give pattern to csv file right.
Please could you give one csv file for my data base 

Selman Kocael

unread,
Aug 3, 2015, 2:10:41 PM8/3/15
to web...@googlegroups.com
you must delete"notnull=True,unique=True".
db_Questions.csv
web2py.mp4

Sai Harsh Tondomker

unread,
Aug 4, 2015, 12:02:02 AM8/4/15
to web...@googlegroups.com
Thanks a lot man that video is very helpful.
Could you do last favor, I want to add more question types for now it's only multiple options.
Could you say how can I ass true or false type ? Like if answer is true or false display true/ false type else multiple answer type question.

Sai Harsh Tondomker

unread,
Aug 6, 2015, 9:21:32 AM8/6/15
to web...@googlegroups.com
I have did same thing which you have shown me in video it show the error message 
unable to parse csv file
"UNIQUE constraint failed: Questions.quesno"

What I need to do for these.
Please help me to solve the problem.
Waiting for your response.

Selman Kocael

unread,
Aug 6, 2015, 9:46:48 AM8/6/15
to web...@googlegroups.com
1. delete notnull=True,unique=True in models.
2. in shell write: db.Questions.drop() and enter.
3. import csv file.

Sai Harsh Tondomker

unread,
Aug 6, 2015, 9:49:44 AM8/6/15
to web...@googlegroups.com
It's working do I need to do every time db.Questions.drop() in shell ????????

Selman Kocael

unread,
Aug 6, 2015, 10:02:25 AM8/6/15
to web...@googlegroups.com
no. 

i don't know its reason, if you edit a table (ie. to delete a validator), it doesn't edit table in sqlite. you must delete the table for one time. 
Reply all
Reply to author
Forward
0 new messages