Python/Django

4. Django 모델 및 관리자

상쾌한기분 2019. 11. 7. 16:40
728x90
반응형

모델 클래스 생성

polls/models.py

from django.db import models


# Create your models here.

class Users(models.Model):
    id = models.IntegerField(primary_key = True, null = False, auto_created = True)
    name = models.CharField(max_length = 10, null = False, unique = True)
    regDate = models.DateTimeField(null = False)

    def __str__(self):
        return "Name : {name}, RegDate : {regDate}".format(name = self.name, regDate = self.regDate)

    # db_prefix 삭제하는 방법 검색 했더니 요런게 있었다... 띠용
    # https://docs.djangoproject.com/en/dev/ref/models/options/#
    class Meta:
        db_table = 'users'  # Options.db_table; The name of the database table to use for the model
        # indexes = [
        #     models.Index(fields = ['last_name', 'first_name']),
        #     models.Index(fields = ['first_name'], name = 'first_name_idx'),
        # ]


class StockHistory(models.Model):
    idx = models.IntegerField(primary_key = True, null = False, auto_created = True)
    productCd = models.CharField(max_length = 10, null = False)
    type = models.CharField(max_length = 4, null = False)
    content = models.CharField(max_length = 100, null = False)
    which = models.CharField(max_length = 10, null = False)
    regDate = models.DateTimeField(null = False)

    def __str__(self):
        return "ProductCd : {productCd}, Content : {content}".format(productCd = self.productCd, content = self.content)

    class Meta:
        db_table = 'stk_his'

 

관리자 사이트 접속을 위해서 테이블 생성

polls/admin.py

from django.contrib import admin

# Register your models here.
from polls.models import StockHistory

admin.site.register(StockHistory)

 

관리자 사이트 접속

http://192.168.1.229:8000/admin/

728x90
반응형