반응형

5.1 새로운 애플리케이션 만들기

5.1.1 애플리케이션 설계하기

5.1.2 프로젝트 뼈대 만들기 애플리케이션 추가

경로 이동

C:\Users\NB-0308>cd ..

 

C:\Users>cd ..

 

C:\>cd project

 

C:\project>cd webprogram

 

C:\project\webprogram>dir

 C 드라이브의 볼륨에는 이름이 없습니다.

 볼륨 일련 번호: FCA3-2376

 

 C:\project\webprogram 디렉터리

 

2020-06-22  오후 02:53    <DIR>          .

2020-06-22  오후 02:53    <DIR>          ..

2020-06-22  오전 11:40    <DIR>          ch3

2020-06-24  오전 11:14    <DIR>          ch4

               0개 파일                   0 바이트

               4개 디렉터리  137,605,287,936 바이트 남음

 

C:\project\webprogram>django-admin startproject mysite

 

C:\project\webprogram>dir

 C 드라이브의 볼륨에는 이름이 없습니다.

 볼륨 일련 번호: FCA3-2376

 

 C:\project\webprogram 디렉터리

 

2020-06-24  오후 02:03    <DIR>          .

2020-06-24  오후 02:03    <DIR>          ..

2020-06-22  오전 11:40    <DIR>          ch3

2020-06-24  오전 11:14    <DIR>          ch4

2020-06-24  오후 02:03    <DIR>          mysite

               0개 파일                   0 바이트

               5개 디렉터리  137,605,050,368 바이트 남음

 

C:\project\webprogram>dir mysite

 C 드라이브의 볼륨에는 이름이 없습니다.

 볼륨 일련 번호: FCA3-2376

 

 C:\project\webprogram\mysite 디렉터리

 

2020-06-24  오후 02:03    <DIR>          .

2020-06-24  오후 02:03    <DIR>          ..

2020-06-24  오후 02:03               647 manage.py

2020-06-24  오후 02:03    <DIR>          mysite

               1개 파일                 647 바이트

               3개 디렉터리  137,605,050,368 바이트 남음

 

C:\project\webprogram>dir mysite\mysite

 C 드라이브의 볼륨에는 이름이 없습니다.

 볼륨 일련 번호: FCA3-2376

 

 C:\project\webprogram\mysite\mysite 디렉터리

 

2020-06-24  오후 02:03    <DIR>          .

2020-06-24  오후 02:03    <DIR>          ..

2020-06-24  오후 02:03               405 asgi.py

2020-06-24  오후 02:03             3,208 settings.py

2020-06-24  오후 02:03               769 urls.py

2020-06-24  오후 02:03               405 wsgi.py

2020-06-24  오후 02:03                 0 __init__.py

               5개 파일               4,787 바이트

               2개 디렉터리  137,605,050,368 바이트 남음

 

C:\project\webprogram>move mysite ch5

        1개의 디렉터리를 이동했습니다.

 

C:\project\webprogram\ch5>python manage.py startapp books

 

C:\project\webprogram\ch5>dir books

 C 드라이브의 볼륨에는 이름이 없습니다.

 볼륨 일련 번호: FCA3-2376

 

 C:\project\webprogram\ch5\books 디렉터리

 

2020-06-24  오후 04:02    <DIR>          .

2020-06-24  오후 04:02    <DIR>          ..

2020-06-24  오후 04:02                66 admin.py

2020-06-24  오후 04:02                90 apps.py

2020-06-24  오후 04:02    <DIR>          migrations

2020-06-24  오후 04:02                60 models.py

2020-06-24  오후 04:02                63 tests.py

2020-06-24  오후 04:02                66 views.py

2020-06-24  오후 04:02                 0 __init__.py

               6개 파일                 345 바이트

               3개 디렉터리  137,512,517,632 바이트 남음

 

 

C:\project\webprogram\ch5>dir polls

 C 드라이브의 볼륨에는 이름이 없습니다.

 볼륨 일련 번호: FCA3-2376

 

 C:\project\webprogram\ch5\polls 디렉터리

 

2020-06-24  오후 04:08    <DIR>          .

2020-06-24  오후 04:08    <DIR>          ..

2020-06-24  오후 04:08                66 admin.py

2020-06-24  오후 04:08                90 apps.py

2020-06-24  오후 04:08    <DIR>          migrations

2020-06-24  오후 04:08                60 models.py

2020-06-24  오후 04:08                63 tests.py

2020-06-24  오후 04:08                66 views.py

2020-06-24  오후 04:08                 0 __init__.py

               6개 파일                 345 바이트

               3개 디렉터리  137,508,081,664 바이트 남음

settings.py

INSTALLED_APPS = [
   
'django.contrib.admin',
   
'django.contrib.auth',
   
'django.contrib.contenttypes',
   
'django.contrib.sessions',
   
'django.contrib.messages',
   
'django.contrib.staticfiles',
   
'polls.apps.PollsConfig',#추가
   
'books.apps.BooksConfig', #추가
]

 

 

C:\project\webprogram\ch5>cd books

models.py

 

from django.db import models

# Create your models here.
from django.db import models

class Book(models.Model):
    title = models.CharField(
max_length=100)
    authors = models.ManyToManyField(
'Author')
    publisher = models.ForeignKey(
'Publisher' , on_delete=models.CASCADE)
    publication_date = models.DateField()

   
def __str__(self):
       
return self.title

admin.py
class Author(models.Model):
    name = models.CharField(
max_length=50)
    salutation = models.CharField(
max_length=100)
    email = models.EmailField()

   
def __str__(self):
       
return self.name


class Publisher(models.Model):
    name = models.CharField(
max_length = 50)
    address = models.CharField(
max_length=100)
    website = models.URLField()

   
def __str__(self):
       
return self.name

 

 

 

from django.contrib import admin

# Register your models here.
from django.contrib import admin
from books.models import Book, Author,Publisher

admin.site.register(Book)
admin.site.register(Author)
admin.site.register(Publisher)

C:\project\webprogram\ch5>python manage.py makemigrations

Migrations for 'books':

  books\migrations\0001_initial.py

    - Create model Author

    - Create model Publisher

    - Create model Book

 

C:\project\webprogram\ch5>python manage.py migrate

Operations to perform:

  Apply all migrations: admin, auth, books, contenttypes, sessions

Running migrations:

  Applying contenttypes.0001_initial... OK

  Applying auth.0001_initial... OK

  Applying admin.0001_initial... OK

  Applying admin.0002_logentry_remove_auto_add... OK

  Applying admin.0003_logentry_add_action_flag_choices... OK

  Applying contenttypes.0002_remove_content_type_name... OK

  Applying auth.0002_alter_permission_name_max_length... OK

  Applying auth.0003_alter_user_email_max_length... OK

  Applying auth.0004_alter_user_username_opts... OK

  Applying auth.0005_alter_user_last_login_null... OK

  Applying auth.0006_require_contenttypes_0002... OK

  Applying auth.0007_alter_validators_add_error_messages... OK

  Applying auth.0008_alter_user_username_max_length... OK

  Applying auth.0009_alter_user_last_name_max_length... OK

  Applying auth.0010_alter_group_name_max_length... OK

  Applying auth.0011_update_proxy_permissions... OK

  Applying books.0001_initial... OK

Applying sessions.0001_initial... OK

 

 

 

 

출처: Django로 배우는 쉽고 빠른 웹 개발 파이썬 웹 프로그래밍

반응형

+ Recent posts