4

I need a way to import a cvs of data into my database. the csv matches one of my models in terms of fields. in Django are there any recommend ways/packages for doing something like this?

I have looked at django-csvimport found here (http://pypi.python.org/pypi/django-csvimport/0.9) however, for a beginner like me there are no tutorials on using it. anyothers with good documentation?

Prometheus
  • 32,405
  • 54
  • 166
  • 302

2 Answers2

3

If it's simple, just follow this example for reading lines of CSV:

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

And on each loop construct your model and save it. It's the quickest and easiest way of doing what you want to do. About 10 lines and not using any fancy libraries. No need to over-think it.

Joe
  • 46,419
  • 33
  • 155
  • 245
  • 1
    My CSV has around 5000 new records each time would this be ok. any issues you foresee? – Prometheus Jan 04 '13 at 14:19
  • 1
    Try it and see. 5000 isn't that many. You may see your database server thrashing a bit, in which case wrapping the whole operation in a transaction may help. – Joe Jan 04 '13 at 14:24
1

You can have a look at django-adaptors and use a CsvDBModel.

The doc gives some hint about it here

trez
  • 478
  • 4
  • 10