おうちインフラ

主に自宅のインフラ周りのメモ

django 開発 ~ モデル

モデル

  • csm
(venv) ~/G/g/c/TAM (main|✚3…) $ python manage.py startapp cms
  • TAM/settings.py
# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'cms.apps.CmsConfig',
]
  • makemigrations
(venv) ~/G/g/c/TAM (main|●1✚4…) $ python manage.py makemigrations cms
Migrations for 'cms':
  cms/migrations/0001_initial.py
...
  • sqlmigrate
(venv) ~/G/g/c/TAM (main|●1✚4…) $ python manage.py sqlmigrate cms 0001
BEGIN;
--
-- Create model CryptoCurrency
--
CREATE TABLE "cms_cryptocurrency" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "symbol" varchar(255) NOT NULL, "brand" varchar(255) NOT NULL, "shares" integer NOT NULL, "average_cost" integer NOT NULL, "market_value" integer NOT NULL, "gain_or_loss" integer NOT NULL, "comment" text NOT NULL);
--
...
  • migrate
(venv) ~/G/g/c/TAM (main|●1✚4…) $ python manage.py migrate cms
Operations to perform:
  Apply all migrations: cms
Running migrations:
  Applying cms.0001_initial... OK
from django.contrib import admin
from cms.models import TotalAsset, Stock, CryptoCurrency

admin.site.register(TotalAsset)
admin.site.register(Stock)
admin.site.register(CryptoCurrency)