Django III에서 다루게 될 내용은 다음과 같습니다.
4-1 Django custom user profile
4-2 User-submitted content
4-3 Finishing touches
4-2 User-submitted content
(1) Creating a vote model
Vote model을 models.py에 추가
다음과 같이 코드를 추가합니다.
mysite > main > models.py

Migrations 수행
다음 명령을 수행합니다.
>python manage.py makemigrations
>python manage.py migrate
Vote model을 폼에 연결
다음과 같이 코드를 추가합니다.
mysite > main > forms.py


VoteForm을 product 함수에 추가
다음과 같이 코드를 추가합니다.
mysite > main > views.py


(2) Adding the vote form to the products page
Bootstrap collapse를 product.html에 추가
다음과 같이 코드를 추가합니다.
mysite > main > templates > main > products.html


script를 product.html에 추가
다음과 같이 코드를 추가합니다.
mysite > main > templates > main > products.html

style를 products.html에 추가

브라우저에서 확인해 봅니다.

(3) Handling the vote form submission
views.py에 product 기능 업데이트
다음과 같이 코드를 추가합니다.
mysite > main > views.py

브라우저에서 확인해 봅니다.

(4) Displaying the product scores
models.py에 Product model 업데이트
다음과 같이 코드를 추가합니다.
mysite > main > models.py

Function을 Vote 모델에 추가
다음과 같이 코드를 추가합니다.
mysite > main > models.py


Migrations 수행
다음 명령을 수행합니다.
>python manage.py makemigrations
>python manage.py migrate
views.py에 products view 업데이트
다음과 같이 코드를 추가합니다.
mysite > main > views.py

products.html에서 products에 user score 추가
다음과 같이 코드를 추가합니다.
mysite > main > views.py

home.html에서 products에 user score 추가
mysite > main > templates > main > home.html

브라우저에서 확인해 봅니다.

브라우저에서 확인해 봅니다.
