Tuesday, March 31, 2015

Re: importing csv data into database

Is it a one-time import or are you looking to have a form that accepts CSV files?

Either way, I would start with the Python csv module. Works really well and should be able to convert your CSV file to a standard Python list of lists, which you should be able to coerce into models, etc.

https://docs.python.org/2/library/csv.html

Write a small script outside of Django that reads a file representing the typical CSV format you are expecting. Once that is working, you can incorporate the code from that script into a model or form. If you only need to import a CSV file one time, just modify that script to bootstrap the Django libraries and modules, then create your model instances from there.

You can also write directly to SQLite directly at that point if needed.

-James

On Mar 31, 2015 4:46 PM, "sum abiut" <suabiut@gmail.com> wrote:
Hi,
Could someone please advise this i am trying to import data from csv file or write to database but i am confuse on how to start. i am using sqllite database.

Cheers,


--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPCf-y5Nk_ATFgYk-hduiLsrxBasS%3Dzu4Qj8Gp5F9vo%3DNRwF%2BA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciW7kXzcSWoL7DC8-jX5PqdkJeqyaPuAqwnvRNcfyJwULg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment