Django:CSV模型导入 [英] Django: CSV model import

查看:167
本文介绍了Django:CSV模型导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种将数据cvs导入我的数据库的方法。 csv匹配我的一个模型的字段。在Django有没有任何建议的方式/包做这样的事情?

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?

我已经看过django-csvimport在这里找到(http://pypi.python.org/ pypi / django-csvimport / 0.9)然而,对于像我这样的初学者,没有使用它的教程。任何其他有良好文件的人

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?

推荐答案

如果很简单,请按照以下示例阅读CSV行:

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

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

在每个循环中构建您的模型并保存它。这是做你想要做的最快速和最简单的方式。大约10行,不使用任何花哨的图书馆。不需要过分的考虑。

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.

这篇关于Django:CSV模型导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆