LoginSignup
2
3

More than 3 years have passed since last update.

Djangoでcsvをモデルに入れるにはどのライブラリが良いのか

Last updated at Posted at 2019-08-09

比較対象のライブラリ

https://kurozumi.github.io/django-import-export/
https://pypi.org/project/django-csvimport/

今回の観点

  • admin画面から、csvがアップロードできること。
  • csvのheaderからmodelのプロパティを指定できる。
  • 型の判定をある程度やってくれる。
  • 重複するデータがあったら弾きたいので、モデル(データベースに)には制約がついて欲しい。

マイグレーション機能

  • django-csvimportにはmigration用のコマンドがある。

ここで自問自答
本当に、migratioコマンドって必要?modelを一回定義してほぼ変わらないのならそれでいいんじゃない?
csvからmodelを作ることってある?
geodjangoのloaderは確かによく使うし便利だなと思う。
loaderはどこまで共通化されているんだろう。
微妙なのがあったら自前で作る?

管理画面からGUI

結論を言うとdjango-csvimportはcsvの読み込みで、「,,,,,」のように連続して値がないcsvは読み込めないバグがありました。
django-import-exportの方が圧倒的にメンテナンスされてて使いやすかったです。

参考

"window","url","title","hostname"
"django_csv_import_ex","http://www.soumu.go.jp/denshijiti/code.html","総務省|電子自治体|全国地方公共団体コード","soumu.go.jp"
"django_csv_import_ex","http://jusyo.jp/tsv/new.php","住所データTSV【住所.jp】","jusyo.jp"
"django_csv_import_ex","https://photo-tea.com/p/aws-ec2-to-rds-csv/","AWSのRDSのmySQLにCSVを一括入力する(EC2経由)|おちゃカメラ。","photo-tea.com"
"django_csv_import_ex","https://messytables.readthedocs.io/en/latest/","messytables: all your rows are belong to us — messytables 0.3 documentation","messytables.readthedocs.io"
"django_csv_import_ex","https://github.com/edcrewe/django-csvimport","edcrewe/django-csvimport: A generic CSV import tool for django models, imports run via admin upload logging model or custom command","github.com"
"django_csv_import_ex","https://djangosnippets.org/snippets/633/","djangosnippets: CSVImport","djangosnippets.org"
"django_csv_import_ex","http://osksn2.hep.sci.osaka-u.ac.jp/~taku/osx/python/encoding.html","Python でUTF-8, shift_jis, euc_jpなど日本語を使う方法","osksn2.hep.sci.osaka-u.ac.jp"
"django_csv_import_ex","https://qiita.com/okadate/items/c36f4eb9506b358fb608","PythonでCSVの読み書き - Qiita","qiita.com"
"django_csv_import_ex","chrome://newtab/","新しいタブ","newtab"
"django_csv_import_ex","https://qiita.com/ysdyt/items/9ccca82fc5b504e7913a","データ分析で頻出のPandas基本操作 - Qiita","qiita.com"
"django_csv_import_ex","https://qiita.com/redAlgae/items/5a7973ed3338d2a100b2","【Python】pandasで日本語のcsvを文字化けせずに読み込む(さらに日本語で書かれた列を抽出する) - Qiita","qiita.com"
"django_csv_import_ex","https://qiita.com/drafts/e590f918fde1324f55bd/edit","「Djangoでcsvをモデルに入れるにはどのライブラリが良いのか」を編集 - Qiita","qiita.com"
"django_csv_import_ex","https://blog.daisukekonishi.com/post/django-import-export-csv/","django-import-exportで管理画面からCSVをインポートできるようにした · PengNote - 勉強した事や行った場所の感想を書くブログ","blog.daisukekonishi.com"
"django_csv_import_ex","https://django-import-export.readthedocs.io/en/latest/api_resources.html","Resources — django-import-export 1.2.1.dev0 documentation","django-import-export.readthedocs.io"
"django_csv_import_ex","https://django-import-export.readthedocs.io/en/latest/import_workflow.html","Import data workflow — django-import-export 1.2.1.dev0 documentation","django-import-export.readthedocs.io"
"django_csv_import_ex","https://qiita.com/myzkyy/items/25cff9374aa8f6565b50","pgloaderでMySQLからPostgreSQLに移行する - Qiita","qiita.com"

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3