LoginSignup
2
4

More than 5 years have passed since last update.

Django の小技とパッケージまとめ

Posted at

この記事について

自分が普段使っているようなパッケージやコマンドのメモです。

パッケージ

共通

pip install django django-cors-headers django-debug-toolbar django-filter djangorestframework djangorestframework-camel-case drf-yasg

プロダクション

pip install gunicorn django-storages
django-storages は Google Cloud Storage だと バグってしまい CSS などの path がちゃんと表現されないので https://github.com/gregmccoy/django-storages を使っている。( 現在は不明 )
インストール方法は pip install git+https://github.com/gregmccoy/django-storages --upgrade

小技

Django Admin User

  1. manage.py でスーパーユーザー作る
  2. python3 manage.py dumpdata auth.User --indent 4 > app/fixtures/initial_data.json でプロジェクト作成時にできるアプリケーションのディレクトリにフィクスチャを入れる
  3. 読み込みは python manage.py loaddata ./app/fixtures/initial_data.json で行う(スーパーユーザーは明示的に fixture ファイルを指定する)

receiver

  1. Model.objects.filter(col=col).update(col=col) でモデルを更新すると post_save シグナルを発信しない

便利なパッケージ

django-cleanup

django-cleanup は pip で入れて INSTALLED_APPS に追記するだけで ImageField 等で登録したファイルで不要なものは自動的に削除される

django-mptt

django-mptt は木構造(カテゴリーなど)を表現したい時に便利

django-channels

django-channels は websocket を利用できるようにする。ただし本番で使うには uwsgi とかむずそう…。

graphene-django

graphene-django は GraphQL を利用できるようにする。ただし n + 1 問題を解決してなさそう。

django-constance

django-constance は動的に共通の設定を持ちたいときに使えそう。ただし DB や redis で管理されるので git 管理できない点は注意。

2
4
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
4