Tuesday, March 31, 2015

Re: importing csv data into database

Thanks guys,
appreciate your help. Yes i am looking to have a form that accepts CSV files. I will have a read on the link that you guys have provided and see how it goes.

Cheers


On Wed, Apr 1, 2015 at 11:44 AM, Andrew Farrell <armorsmith42@gmail.com> wrote:
Hello Sum,

There are two approaches you could take.
One is to install a plugin like django-import-export and then use it's import functionality. Its been a while since I've done this, but when I did under django-1.4 it Just Worked. This is the best approach if you know your data is clean and doesn't require any sort of processing before saving it.

The other is to write a custom manage.py command. This would let you load the data using a csv.DictReader, do some logic on it, and then bulk-create objects in the database. This approach has the disadvantage that if you have a bug in your processing script, you will end up adding messy data to your database and having to clean it up. To avoid this, you could write a unit test case which calls your import function in its setUp() method. This testcase would create a separate test database, import the data into it, run your test functions, and then clear the test database. This approach would also let you, for example, deliberately insert malformed info into the data and verify that your import function would catch those errors.

On Tue, Mar 31, 2015 at 6: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%2By5TLbaBcs8%2BrJsNmXFknRGNTC5%2BOr3URs53eiFBM8GLekmcA%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/CAPCf-y66m%3DbH0ddOWmqy2AxST-C4E4btS3T4Ce0MmHb0o-OGqw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment