1

I know how to import txt files to mysql. But since I'm using Django now, I created a model called dataset. How can I import the data.txt to the dataset model in Django? Each row of the data.txt file consists of several columns, each of which corresponds to one field of the model.

I'm using Django with MySQL.

Any code or hint would be appreciated.

paul marcus
  • 43
  • 1
  • 5
  • Possibly [this](http://stackoverflow.com/questions/2459979/how-to-import-csv-data-into-django-models) could help maybe. – woofmeow Aug 04 '13 at 01:57
  • 1
    Did you already read [the section on providing initial data for models](https://docs.djangoproject.com/en/1.5/howto/initial-data/) in the documentation? – Burhan Khalid Aug 04 '13 at 07:10

1 Answers1

0

I have done something similar.

You should create a python script that read you input file and create the Model object(which translate in a record in your database). It would be the same thing as using the django-shell

This link is a bit old but explains the concept. You want to adapt it to your version of Django ie: using setup_environ

http://www.cotellese.net/2007/09/27/running-external-scripts-against-django-models/

Djanux
  • 301
  • 1
  • 4
  • 10