Djnagoの管理画面からCSVファイルをアップしてデータ登録
今回は restaurants というアプリを作成し進めていきます。 CSVのファイルは管理画面のレストランの一覧画面 http://127.0.0.1:8000/admin/restaurants/restaurant/ からアップ。 アプリの作成 python manage.py startapp restaurants モデルは restaurant で作成。 Admin テンプレートの Override templatesフォルダは manage.py と同じ階層に作成。 templates/admin/restaurants/restaurant/change_list.html を作成 {% extends 'admin/change_list.html' %} {% load static %} {% block content %} <a href="upload-csv/">Upload a csv file</a> {{ block.super }} {% endblock %} {{ block.super }} は親のテンプレートコンテンツ。 Django change_list.html Custom Admin Page の作成 上記で作成したリンク先の upload-csv/ の URL を設定 restaurants/admin.py の RestaurantAdmin で get_urls()を設定。 def get_urls(self): urls = super().get_urls() new_urls = [ path('upload-csv/', self....