1. Article 생성
1) web > models.py에 입력
from django.db import models
class Guest(models.Model):
title = models.CharField(max_length=50);
content = models.TextField();
regdate = models.DateField(auto_now_add=True);
class Article(models.Model):
id = models.AutoField(primary_key=True);
name = models.CharField(max_length=30);
price = models.IntegerField();
pub_date = models.DateField(auto_now=True);
2) web > admin.py에 입력
from django.contrib import admin
from web.models import Guest, Article
class GuestAdmin(admin.ModelAdmin):
list_display = ('id','title','content','regdate');
admin.site.register(Guest,GuestAdmin);
class ArticleAdmin(admin.ModelAdmin):
list_display = ('id','name','price','pub_date');
admin.site.register(Article,ArticleAdmin);
2. 서버 연결
python manage.py runserver 80
브라우저에 127.0.0.1/admin 입력
Article이 추가된 것을 확인 가능
🔪 migration하기 위해 Ctrl + C 해서 서버 연결 끊기
3. migration
python manage.py makemigrations
python manage.py migrate
Heidi에서도 sql문이 생성된 것을 확인 가능