Another approach is to use postgres' COPY command:

https://www.postgresql.org/docs/9.6/static/sql-copy.html

which knows how to parse and import tab-delimited files (and is crazy 
fast). Then, once the table exists, use Django's `inspectdb` management 
command to generate a Model corresponding to the table. It may need a 
little manual massaging afterwards, but I've done this on several projects 
and it works very well for most purposes.

./s


On Monday, January 8, 2018 at 6:38:44 PM UTC-8, Tom Tanner wrote:
>
> I have a tab-delimited data file that looks something like this:
>
>
> NAME S1903_C02_001E state county tract State-County-Tract-ID
> Census Tract 201, Autauga County, Alabama 66000 01 001 020100 01001020100
> Census Tract 202, Autauga County, Alabama 41107 01 001 020200 01001020200
> Census Tract 203, Autauga County, Alabama 51250 01 001 020300 01001020300
>
> I want to make a Django model named `MyModel` with three columns: "name", 
> "data", and "geoid", which correspond to the file's columns "NAME", 
> "S1903_C02_001E", and "State-County-Tract-ID." Can I do this via command 
> line, or with a custom Python script? I'm running my Django project locally 
> on a computer running Debian 9.3. 
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/708e0f1d-1cac-4321-a68e-697a4a8cd3da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to