%cd ch3
/Users/re4lfl0w/Documents/ipython/books/django_python_web_programming/ch3
%ll
total 288 -rw-r--r-- 1 re4lfl0w staff 143360 4 16 06:49 db.sqlite3 -rwxr-xr-x 1 re4lfl0w staff 249 4 16 01:19 manage.py* drwxr-xr-x 10 re4lfl0w staff 340 4 16 06:12 mysite/ drwxr-xr-x 14 re4lfl0w staff 476 4 16 05:55 polls/ drwxr-xr-x 3 re4lfl0w staff 102 4 16 05:57 templates/
!python manage.py startapp books
!tree
. ├── books │ ├── __init__.py │ ├── admin.py │ ├── migrations │ │ └── __init__.py │ ├── models.py │ ├── tests.py │ └── views.py ├── db.sqlite3 ├── manage.py ├── mysite │ ├── __init__.py │ ├── __init__.pyc │ ├── settings.py │ ├── settings.pyc │ ├── urls.py │ ├── urls.pyc │ ├── wsgi.py │ └── wsgi.pyc ├── polls │ ├── __init__.py │ ├── __init__.pyc │ ├── admin.py │ ├── admin.pyc │ ├── models.py │ ├── models.pyc │ ├── templates │ │ └── polls │ │ ├── detail.html │ │ ├── index.html │ │ └── results.html │ ├── tests.py │ ├── urls.py │ ├── urls.pyc │ ├── views.py │ └── views.pyc └── templates └── admin └── base_site.html 8 directories, 31 files
컬럼명 | 타입 | 제약조건 | 설명 |
---|---|---|---|
id | integer | NotNull, PK, AutoIncrement | Primary Key |
title | varchar(100) | NotNull | 책 제목 |
authors | integer | NotNull, FK(Author.id), index | Many-To-Many |
publisher | integer | NotNull, FK(Publisher.id), index | Foreign Key |
publication_date | date | NotNull | 책 출판일 |
컬럼명 | 타입 | 제약조건 | 설명 |
---|---|---|---|
id | integer | NotNull, PK, AutoIncrement | Primary Key |
salutation | varchar(100) | NotNull | 저자 인사말 |
name | varchar(50) | NotNull | 저자 성명 |
NotNull | 저자 이메일 |
컬럼명 | 타입 | 제약조건 | 설명 |
---|---|---|---|
id | integer | NotNull, PK, AutoIncrement | Primary Key |
name | varchar(50) | NotNull | 출판사 이름 |
address | varchar(200) | NotNull | 출판사 주소 |
website | url | NotNull | 출판사 홈페이지 |
URL | View | Template |
---|---|---|
/books/ -> | BooksModelView.as_view() -> | index.html |
/books/book/ -> | BookList.as_view() -> | book_list.html |
/books/book/3/ -> | BookDetail.as_view() -> | book_detail.html |
!python manage.py makemigrations
Migrations for 'books': 0001_initial.py: - Create model Author - Create model Book - Create model Publisher - Add field publisher to book
!python manage.py migrate
Operations to perform: Synchronize unmigrated apps: polls Apply all migrations: admin, contenttypes, books, auth, sessions Synchronizing apps without migrations: Creating tables... Installing custom SQL... Installing indexes... Running migrations: Applying books.0001_initial... OK
!git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
books/migrations/0001_initial.py
nothing added to commit but untracked files present (use "git add" to track)
URL 패턴 | 뷰 클래스명 | 템플릿 파일명 | 템플릿 설명 |
---|---|---|---|
/books/ | BooksModelView | index.html | books 애플리케이션 첫 화면 |
/books/book/ | BookLIst | book_list.html | 책의 리스트를 보여줌 |
/books/author/ | AuthorList | author_list.html | 저자의 리스트를 보여줌 |
/books/publisher/ | PublisherList | publisher_list.html | 출판사의 리스트를 보여줌 |
/books/book/3/ | BookDetail | book_detail.html | 특정 책의 상세 정보를 보여줌 |
/books/author/3/ | AuthorDetail | author_detail.html | 특정 저자의 상세 정보를 보여줌 |
/books/publisher/3/ | PublisherDetail | publisher_detail.html | 특정 출판사의 상세 정보를 보여줌 |
URL 패턴 | 기존 뷰 이름 (함수형 뷰) |
새로운 뷰 이름 (클래스형 뷰) |
변경사항(템플릿 파일명은 동일함) |
---|---|---|---|
/polls/ | index() | IndexView | 뷰와 템플릿 모두 변경함(index.html) |
/polls/5/ | detail() | DetailView | 뷰와 템플릿 모두 변경함(detail.html) |
/polls/5/results/ | results() | ResultsView | 뷰와 템플릿 모두 변경함(results.html) |
/polls/5/vote/ | vote() | vote() | 뷰와 템플릿 모두 변경사항 없음 |
URL 패턴 | 기존 뷰 이름 (함수형 뷰) |
새로운 뷰 이름 (클래스형 뷰) |
지네릭 뷰 선택 |
---|---|---|---|
/polls/ | index() | IndexView | 질문 리스트를 보여주는 로직이므로, ListView를 사용함 |
/polls/5/ | detail() | DetailView | 질문 하나에 대한 세부 정보를 보여주는 로직이므로, DetailView를 사용함 |
/polls/5/results/ | results() | ResultsView | 투표 결과도 각 질문에 대한 세부 정보에 해당하므로, DetailView를 사용함 |
/polls/5/vote/ | vote() | vote() | 뷰와 템플릿 모두 변경사항 없음 |
class IndexView(ListView):
template_name = 'polls/index.html'
context_object_name = 'latest_question_list'
def get_queryset(self):
'''Return the last five published questions.'''
return Question.objects.order_by('-pub_date')[:5]
!git status
On branch master Untracked files: (use "git add <file>..." to include in what will be committed) books/migrations/0001_initial.py logs/ nothing added to commit but untracked files present (use "git add" to track)