Bulk Creating Django Models from CSV File?

867 views
Skip to first unread message

Victor Hooi

unread,
Apr 2, 2012, 1:24:13 AM4/2/12
to django...@googlegroups.com
Hi,

I have several large CSV files that I'm hoping to parse, and use to create Django objects. Each line looks might look something like this:

"Server Hostname", "Classification", "Country", "Operating System"
"foo.bar.com", "Prod", "Australia", "Solaris"
"alex.john.com", "Dev", "UK", "Linux"
"bob.hope.com", "UAT, "Japan", "Windows

For performance reasons, it would be nice to use something like 1.4's bulk_create:


However, I noticed the caveat about it not populating the auto-incrementing PK field. What's the recommended way to populate the PK field then? How do you use it?

Secondly, the models will have FK relationships to other models (for instance, Classification, Country and Operating System would be stored in a lookup table). What's the best way to look these up, and assign the appropriate FK, whilst still preserving good performance and using bulk inserts?

Cheers,
Victor
Message has been deleted

Thomas Weholt

unread,
Apr 2, 2012, 9:53:53 AM4/2/12
to django...@googlegroups.com
You might want to look at DSE as well. Currently is has some issues
with Django 1.4, but I'll look into fixing those tonight.

https://bitbucket.org/weholt/dse2

Regards,
Thomas Weholt

> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/bP0RG4NXJjEJ.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

--
Mvh/Best regards,
Thomas Weholt
http://www.weholt.org

Reply all
Reply to author
Forward
0 new messages