manage.py dbshell
manage.py inspectdb
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'db_dev',
'USER': 'root',
'PASSWORD': '',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
from django.apps import AppConfig
class TestappConfig(AppConfig):
#nameにprojectを追加する
name = 'testprj.testapp'
INSTALLED_APPS = [
'testprj.testapp.apps.TestappConfig',
]
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
]
#djangoにUserというモデル名は避けるべき
from django.db import models
class AppUser(models.Model):
id = models.BigAutoField(primary_key=True)
created_at = models.DateTimeField()
updated_at = models.DateTimeField()
name = models.CharField(max_length=256)
class Meta:
managed = False
db_table = 'users'
def __str__(self):
return self.name
from django.contrib.auth.models import *
from django.contrib import admin
from .models.app_user import AppUser
class UserAdmin(admin.ModelAdmin):
list_display = ('id', 'name', 'created_at', 'updated_at', )
list_display_links = ('name', )
admin.site.register(AppUser, UserAdmin)
manage.py createsuperuser