LoginSignup
4
3

More than 5 years have passed since last update.

Djangoのadmin管理画面にデータベースの項目を追加

Last updated at Posted at 2020-09-05

サーバーを起動してadmin画面を確認
初期設定は「グループ」と「ユーザー」のみ。
新規に作成した、テーブル名を表示させる。

サイト管理   Django サイト管理 (2).png
今回アプリケーション名はreportで、モデルはこんな感じです。

models.py
from django.db import models

# Create your models here.
class Company(models.Model):
    name = models.CharField(verbose_name='アカウント名', max_length=255)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

migrateで追加したアプリケーションフォルダの配下のadmin.pyを編集します。

$ {project}/{application}
$ report_site/report

$ vim admin.py
admin.py
from django.contrib import admin

# Register your models here.

#下の2行を追加
# from アプリケーション名.models import マイグレーションのクラス名
from report.models import Company
admin.site.register(Company)

サイト管理   Django サイト管理 (3).png

変更する company を選択   Django サイト管理.png

参考記事

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