ํ’€์Šคํƒ ์›น๐ŸŒ ๊ฐœ๋ฐœ์ž ์ง€๋ง์ƒ ๐Ÿง‘๐Ÿฝโ€๐Ÿ’ป
โž• ์ธ๊ณต์ง€๋Šฅ ๊ด€์‹ฌ ๐Ÿค–


Categories


Recent views

  • 1
  • 2
  • 3
  • 4
  • 5

Django CRUD

  1. Django ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ๊ณผ ๊ฐ€์ƒ ํ™˜๊ฒฝ ์„ค์ •
    • Django ์•ฑ ์ƒ์„ฑ๊ณผ ์ถ”๊ฐ€
      • ๊ธฐ๋ณธ html ํŒŒ์ผ ์„ค์ •
        • Django Read(detail) ์ƒ์„ฑ
          • Django Update ์ƒ์„ฑ

            Django CRUD(Create, Read, Update, Delete ) ๋งŒ๋“ค๊ธฐ

            Django ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ๊ณผ ๊ฐ€์ƒ ํ™˜๊ฒฝ ์„ค์ •

            1. mkdir ๋Œ€์ƒํด๋”์ด๋ฆ„, cd ๋Œ€์ƒํด๋” ์ด๋ฆ„์œผ๋กœ ํด๋”๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์ด๋™ํ•œ๋‹ค
            2. python -m venv venv๋กœ ํ•ด๋‹น ๋””๋ ‰ํ† ๋ฆฌ์— ํด๋”์ด๋ฆ„์˜ ๊ฐ€์ƒํ™˜๊ฒฝ์„ ๋งŒ๋“ค์–ด์คŒ
            3. source venv/Scripts/activate๋กœ ํ„ฐ๋ฏธ๋„์„ ๊ฐ€์ƒํ™˜๊ฒฝ์— ๋“ค์–ด๊ฐ€๊ฒŒ ํ•œ๋‹ค. (deactivate๋กœ ๋‚˜๊ฐ)
              • ๋˜๋Š” vsCode์—์„œ f1์œผ๋กœ select interpreter๋ฅผ ํ†ตํ•˜์—ฌ ๊ฐ€์ƒํ™˜๊ฒฝ ๋“ค์–ด๊ฐ€๊ธฐ ๊ฐ€๋Šฅ
            4. pip install django๋กœ ๊ฐ€์ƒํ™˜๊ฒฝ ๋‚ด์— django๋ฅผ ์„ค์น˜ํ•œ๋‹ค.
            5. django-admin startproject ํ”„๋กœ์ ํŠธ๋ช… . ์œผ๋กœ ํ˜„์žฌ ํด๋” ๋‚ด์— ํ”„๋กœ์ ํŠธ๋ฅผ ๋งŒ๋“ ๋‹ค
              • ๋งˆ์ง€๋ง‰ .์ด ์—†์œผ๋ฉด ํ”„๋กœ์ ํŠธ๋ช…์œผ๋กœ ๋œ ํด๋”๋ฅผ ๋งŒ๋“ค๊ณ  ๊ทธ ๋‚ด๋ถ€์— ๋งŒ๋“ค๊ฒŒ ๋œ๋‹ค.
            6. python manage.py runserver๋กœ ์„œ๋ฒ„๋ฅผ ๋Œ๋ฆฌ๊ณ  ํ™•์ธํ•ด๋ณธ๋‹ค.
              • http://127.0.0.1:8000/ ๊ฐ€ ๊ธฐ๋ณธ ์ฃผ์†Œ , ํ„ฐ๋ฏธ๋„์—์„œ Ctrl + C๋กœ ์„œ๋ฒ„๋ฅผ ๋‹ซ๋Š”๋‹ค
              • ํ„ฐ๋ฏธ๋„์— code .์„ ์น˜๋ฉด ํ•ด๋‹น ๋””๋ ‰ํ† ๋ฆฌ๋กœ VS Code IDE๊ฐ€ ์ผœ์ง(๋ฒ„๊ทธ ์žˆ์Œ)

                Django ์•ฑ ์ƒ์„ฑ๊ณผ ์ถ”๊ฐ€

            7. ๋Œ€์ƒ ํด๋”(๋ณดํ†ต ํ”„๋กœ์ ํŠธ ํด๋”์™€ ๋™์ผ ์œ„์น˜)์—์„œ django-admin startapp ์•ฑ์ด๋ฆ„ ์œผ๋กœ ์•ฑ ์ƒ์„ฑ
              • python manage.py startapp ์•ฑ์ด๋ฆ„ ์œผ๋กœ๋„ ๊ฐ€๋Šฅ
            8. ํ”„๋กœ์ ํŠธ๋ช… ํด๋” ๋‚ด๋ถ€์˜ settings.py์˜ INSTALLED_APPS ๋ฆฌ์ŠคํŠธ์— ์•ฑ์ด๋ฆ„์„ ์ถ”๊ฐ€
              • ๋ณดํ†ต ์ปค์Šคํ…€ app์€ ๋งจ ์œ„์— ๋†“์œผ๋ฉฐ ๋™๋ช…์ผ์‹œ ๋งจ ์œ„์˜ app์ด ์šฐ์„ ์ด๋‹ค.(โ€˜,โ€™ ์ถ”๊ฐ€ ์ฃผ์˜)

                myCRUD ํ”„๋กœ์ ํŠธ ํด๋” ๋‚ด๋ถ€์˜ settings.py์˜ ์ผ๋ถ€
                ```python
                # Application definition

              INSTALLED_APPS = [
              'CRUD', # ์•ฑ ์ด๋ฆ„
              'django.contrib.admin',
              'django.contrib.auth',
              'django.contrib.contenttypes',
              'django.contrib.sessions',
              'django.contrib.messages',
              'django.contrib.staticfiles',
              ]

            3. ๋™์ผํ•œ ํด๋”์˜ urls.py ํŒŒ์ผ ๋‚ด๋ถ€์˜ urlpatterns ๋ฆฌ์ŠคํŠธ์— path()ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด ํ•ด๋‹น ์•ฑ URL ์ถ”๊ฐ€
            	- ๋ณดํ†ต path('์•ฑ์ด๋ฆ„/', include('์•ฑ์ด๋ฆ„.urls')), ๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค (๋’ค์˜ / ์ถ”๊ฐ€ ํ•„์ˆ˜!)
            	- ๊ตณ์ด ์•ฑ์ด๋ฆ„์„ ์“ธํ•„์š” ์—†์ง€๋งŒ ๊ด€๋ก€์™€ ํšจ์œจ ์ƒ ๊ทธ๋ ‡๊ฒŒ ํ•œ๋‹ค.
            	- include()ํ•จ์ˆ˜๋Š” django.urls์—์„œ ์ž„ํฌํŠธ ํ•ด์˜จ๋‹ค.(from django.urls import path, include)
            	> ํ”„๋กœ์ ํŠธ ํด๋”์˜ urls.py์˜ ์ผ๋ถ€
            ```python
            from django.contrib import admin
            from django.urls import path, include
            
            urlpatterns = [
                path('admin/', admin.site.urls),
                path('CRUD/', include('CRUD.urls')),
            ]
            
            
            1. ํ•ด๋‹น ์•ฑ ํด๋” ๋‚ด๋ถ€์— urls.py ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜๊ณ , urlpatterns ๋ฆฌ์ŠคํŠธ๋ฅผ ๋งŒ๋“ ๋‹ค
            2. ํ•„์š” ๋ชจ๋“ˆ๋“ค (django.urls์˜ pathํ•จ์ˆ˜, ํ•ด๋‹น ํด๋”(.)์˜ views ํŒŒ์ผ ๋“ฑ)์„ ์ž„ํฌํŠธ

              ์•ฑ ํด๋” ๋‚ด๋ถ€์˜ ์ƒˆ๋กœ๋งŒ๋“  urls.py ์˜ˆ์‹œ
              ```python
              from django.urls import path
              from . import views

            app_name = 'CRUD' # ์ผ๋ฐ˜์ ์œผ๋กœ ์•ฑ ์ด๋ฆ„๊ณผ ๊ฐ™์€ ์ด๋ฆ„์„ ๋„ฃ์Œ

            urlpatterns = [
            path('create/', views.create, name="create"),
            # variable routing + namespacing
            path('<int:id>/update/', views.update, name="update"),
            # ๊ธฐํƒ€ ํ•„์š”ํ•œ path ์ถ”๊ฐ€
            ]

            ## model์— ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ชจ๋ธ ์ถ”๊ฐ€
            1. ํ•ด๋‹น ์•ฑ ํด๋” ๋‚ด๋ถ€์˜ models.py ํŒŒ์ผ์— ์›ํ•˜๋Š” ์ด๋ฆ„์˜ ๋ชจ๋ธ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ ๋‹ค.
            	- ์ด ํด๋ž˜์Šค๋Š” models.Model์„ ์ƒ์†๋ฐ›์•„์•ผํ•œ๋‹ค.
            2. ๋‚ด๋ถ€์˜ ํด๋ž˜์Šค ๋ณ€์ˆ˜๋กœ ๊ฐ๊ฐ์˜ ์ •๋ณด ํ•„๋“œ๋ฅผ ์„ค์ •ํ•œ๋‹ค.
            	- models.CharField(max_length=)๋Š” ๋ณดํ†ต ์งง์€ ๋‚ด์šฉ์˜ ๋ฌธ์ž์—ด ์ •๋ณด์— ์‚ฌ์šฉํ•˜๋ฉฐ, max_length๋ผ๋Š” ์ตœ๋Œ€ ์ €์žฅ ๊ณต๊ฐ„์„ ๋ฏธ๋ฆฌ ํ• ๋‹นํ•ด์ค˜์•ผ ํ•œ๋‹ค.
            	- models.TextFiled()๋Š” ๋ณดํ†ต ๋ณธ๋ฌธ ๊ฐ™์€ ๊ธด ๊ธธ์ด์˜ ๋ฌธ์ž์—ด ์ •๋ณด์— ์‚ฌ์šฉ, max_length ํ• ๋‹น์ด ํ•„์š” ์—†๋‹ค
            	- models.DateField()๋Š” ๋‚ ์งœ์™€ ์‹œ๊ฐ„ ์ •๋ณด์— ์‚ฌ์šฉํ•œ๋‹ค.
            	- models.BooleanField()๋Š” ์ฐธ, ๊ฑฐ์ง“์œผ๋กœ ๊ตฌ๋ถ„ํ•˜๋Š” ์ •๋ณด์— ์‚ฌ์šฉํ•œ๋‹ค.
            > ํ•ด๋‹น ์•ฑ ํด๋”์˜ models.py ์˜ˆ์‹œ
            ```python
            from django.db import models
            
            # Create your models here.
            class TODO(models.Model): # models.Model ์ƒ์†ํ•ด์ฃผ๊ธฐ ํ•„์ˆ˜
                title = models.CharField(max_length=50)
                content = models.TextField()
                due_date = models.DateField()
                check = models.BooleanField()
                
                def __str__(self): # __str__์„ ์˜ค๋ฒ„๋กœ๋”ฉํ•˜๋ฉด admin์˜ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๊ฐ€์‹œ์„ฑ์ข‹๊ฒŒ ๋ณด์—ฌ์ค„ ์ˆ˜ ์žˆ๋‹ค.
                    return f'{self.due_date}๊นŒ์ง€ {self.title}์ผ์„ ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. ๋‚ด์šฉ : {self.content}, ํ–‰๋™ ์—ฌ๋ถ€ : {self.check}'
            
            
            • ํ•ด๋‹น ๋ฐ์ดํ„ฐํ•„๋“œ์˜ ์ข…๋ฅ˜๋ฅผ ์ž˜ ์„ค์ •ํ•ด์ค˜์•ผ, ๋‚˜์ค‘์— form ์ž๋™ ์ƒ์„ฑ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ๋•Œ ์ ์ ˆํ•˜๊ฒŒ ์ƒ์„ฑ๋œ๋‹ค.
              1. ๋ชจ๋ธ์ด ์™„์„ฑ๋˜๋ฉด ํ„ฐ๋ฏธ๋„์—์„œ python manage.py makemigrations๋ฅผ ํ†ตํ•˜์—ฌ ๋ชจ๋ธ์„ SQL ๋ฒˆ์—ญ๊ธฐ๋กœ ๋ณด๋‚ธ๋‹ค. (์ผ์ข…์˜ ๋ฐ์ดํ„ฐํ‘œ ํ—ค๋” ๋งŒ๋“ค๊ธฐ)
              • ์ด๋•Œ 0001_initial.py๊ฐ€ ์ƒ์„ฑ๋˜๋ฉฐ, ์ง€์šฐ๋ฉด ๋‹ค์‹œ ๋งŒ๋“ค์–ด์ค˜์•ผ ํ•œ๋‹ค.
                1. python manage.py migrate๋ฅผ ํ†ตํ•ด SQL๋กœ ํ•ด์„ํ•œ๋‹ค. (์ผ์ข…์˜ ๋ฐ์ดํ„ฐ ํ‘œ ๊ทธ๋ฆฌ๊ธฐ)
              • ์ด๋•Œ ๋ชจ๋ธ๋ง์„ ์‹ ์ค‘ํžˆํ•˜์—ฌ ๋‚˜์ค‘์— ๋ชจ๋ธ์„ ์ˆ˜์ •ํ•˜๋Š” ์ผ์„ ์—†๋„๋ก ํ•˜์ž.
              • ๋ชจ๋ธ๋ง ์ˆ˜์ •์‹œ ํ•ด๋‹น ๋ชจ๋ธ ํŒŒ์ผ(0001_initial.py)๋ฅผ ์ง€์šฐ๊ณ  ๋‹ค์‹œ ๋งŒ๋“ค์–ด์•ผ ํ•œ๋‹ค.
              • ๋งŒ์•ฝ ๊ธฐ์กด์— ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ํ•ด๋‹น ๋ชจ๋ธ์˜ ์ •๋ณด๊ฐ€ ์žˆ์œผ๋ฉด ๋ฌธ์ œ๋ฅผ ์ผ์œผํ‚จ๋‹ค. (๋‹ค ์ง€์šฐ๊ณ  ์ƒˆ๋กœ ๋ฐ”๊ฟ”์ฃผ๋Š”๊ฒŒ ๋‚˜์Œ)

                ๊ธฐ๋ณธ html ํŒŒ์ผ ์„ค์ •

                1. ํ•ด๋‹น ์•ฑ ํด๋” ๋‚ด๋ถ€์— templates ๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ์ƒˆ ํด๋”๋ฅผ ๋งŒ๋“ ๋‹ค.
                2. ๋‚ด๋ถ€ ํด๋”์— base.html์„ ๋งŒ๋“ค๊ณ  !+tab์œผ๋กœ ๊ธฐ๋ณธ ํ˜•์‹์„ ์žก๋Š”๋‹ค.
                3. <body>ํƒœ๊ทธ ์‚ฌ์ด์— {% block body %}์™€ {% endblock %} DTL ๋ฌธ๋ฒ•์„ ๋„ฃ๋Š”๋‹ค.
              • ์ด๋•Œ ์›ํ•œ๋‹ค๋ฉด bootstrap์„ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜ ์—ฌ๋Ÿฌ๊ฐ€์ง€๋ฅผ ๊พธ๋ฏผ๋‹ค.

                base.html ํŒŒ์ผ ์˜ˆ์‹œ
                ```html
                &#60;!DOCTYPE html&#62;
                &#60;html lang="en"&#62;
                &#60;head&#62;
                &#60;meta charset="UTF-8"&#62;
                &#60;meta name="viewport" content="width=device-width, initial-scale=1.0"&#62;
                &#60;meta http-equiv="X-UA-Compatible" content="ie=edge"&#62;
                &#60;title&#62;MyOwnSuckyBulletin&#60;/title&#62;
                &#60;/head&#62;
                &#60;body&#62;
                {% block body %}
                {% endblock %}
                {% block body2 %}
                {% endblock %}
                &#60;!โ€“์ด๋Ÿฐ ์‹์œผ๋กœ 2๊ฐœ ์ด์ƒ ๋†“์„ ์ˆ˜๋„ ์žˆ๋‹ค.โ€“&#62;
                &#60;!โ€“html ์ฃผ์„ ๋‹ฌ๊ธฐ, ํ•˜์ง€๋งŒ DTL๊ณผ ์ถฉ๋Œ์ด ์ผ์–ด๋‚  ์ˆ˜ ๋„ ์žˆ๋‹ค. โ€“&#62;
                &#60;/body&#62;
                &#60;/html&#62;

            4. base.html๊ณผ ๊ฐ™์€ ํด๋”์— index.html ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์ค€๋‹ค.
            5. {% extends 'base.html' %}, {% block body %}, {% endblock %}๋ฅผ ํ†ตํ•˜์—ฌ base.html์˜ ํ…œํ”Œ๋ฆฟ์„ ๊ฐ€์ ธ์˜จ๋‹ค.
            	- body๋ผ๋Š” ์ด๋ฆ„์„ ๋ฐ”๊พธ๋ฉด ๋‹ค๋ฅธ ์œ„์น˜์˜ ํ…œํ”Œ๋ฆฟ์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋‹ค.
            	- ํ•˜์ง€๋งŒ 2๊ฐœ์ด์ƒ์˜ ํ…œํ”Œ๋ฆฟ์„ ๊ฐ€์ ธ์˜ค๋Š” ๊ฒƒ์€ ํ•  ์ˆ˜ ์—†๋‹ค.
            6. ํ•ด๋‹น ํด๋”์˜ urls.py์˜ urlpatterns์— ๋ฉ”์ธ ํŽ˜์ด์ง€ ํ‘œ์‹œ๋ฅผ ์œ„ํ•œ path๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.
            7.  ํ•ด๋‹น ํด๋”์˜ views.py์— index ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค๊ณ  ์ถ”๊ฐ€ํ•œ ๋ชจ๋ธ๋“ค์„ ์ •๋ ฌ ํ›„ ๋ณ€์ˆ˜์— ์ง‘์–ด๋„ฃ๋Š”๋‹ค.
            8. index ํ•จ์ˆ˜๋กœ index.html ํŒŒ์ผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๋„˜๊ฒจ์ฃผ๊ณ  ์ถœ๋ ฅํ•˜๋Š” html ์ฝ”๋“œ๋ฅผ ๋งŒ๋“ ๋‹ค.
            > urls.py์˜ ์ผ๋ถ€(์•ฑ ๋‚ด๋ถ€ ํด๋”)
            ```python
            urlpatterns = [
                path(&#39;&#39;, views.index, name=&#34;index&#34;), #todos์˜ ๋ฉ”์ธ ํŽ˜์ด์ง€ url์„ ์˜๋ฏธ
                ]
            
            

            views.py (์•ฑ ๋‚ด๋ถ€ ํด๋”)
            ```python
            from django.shortcuts import render
            from .models import TODO

            ์ด์šฉํ•  ๋ชจ๋ธ์„ models.py์—์„œ ๊ฐ€์ ธ์™€์•ผ ํ•œ๋‹ค.

            Create your views here.

            def index(request): # request๋Š” ์š”์ฒญ์ž๊ฐ€ ๋ณด๋‚ธ ์ •๋ณด๋“ค์ด ๋‹ด๊ฒจ์ ธ์žˆ๋‹ค.
            todos = TODO.objects.order_by('due_date').all() # ๋‚ ์งœ์ˆœ์œผ๋กœ ์ •๋ ฌ
            context = { # context๋ผ๋Š” ๋”•์…”๋„ˆ๋ฆฌ ํ˜•ํƒœ๋กœ ๋„ฃ์–ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.
            'todos': todos,
            }
            return render(request, 'index.html', context)

            render ํ•จ์ˆ˜๋Š” ์ •๋ณด์™€ html ์ฝ”๋“œ, ๊ฐ€๊ณต๋œ ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์‚ฌ๋žŒ๋“ค์—๊ฒŒ ๋ณด์—ฌ์ค„ ํŽ˜์ด์ง€๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.

            - ๋ชจ๋ธ ํด๋ž˜์Šค ๋‚ด๋ถ€์˜ ํ•จ์ˆ˜๋“ค
            	- ๋ชจ๋ธ.objects.all(count) : ํด๋ž˜์Šค์˜ ๋ชจ๋“  ๊ฐ์ฒด๋ฅผ ์ถœ๋ ฅ, count๋ฅผ ๋นˆ์นธ์œผ๋กœ ๋†“์ง€ ์•Š์œผ๋ฉด, count๋ฒˆ์งธ ์š”์†Œ๋ฅผ ๊ฐ€์ ธ์˜จ๋‹ค.
            	
            	- ๋ชจ๋ธ.objects.get(id=count, title="content"): 1๊ฐœ์˜ ๋ฐ์ดํ„ฐ ๊ฐ์ฒด๋งŒ ๊ฐ€์ ธ์˜จ๋‹ค. id์— ๊ฐ’์„ ์ง€์ •ํ•˜๋ฉด, id๊ฐ€ 1์ธ ๊ฐ์ฒด ํ•˜๋‚˜, content๋ฅผ ์ง€์ •ํ•˜๋ฉด ํ•ด๋‹น content๋ฅผ title๋กœ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๋ฐ์ดํ„ฐ ๊ฐ์ฒด๋ฅผ ๊ฐ€์ ธ์˜จ๋‹ค. ์ผ์น˜ํ•˜๋Š” ๊ฐ์ฒด๊ฐ€ 2๊ฐœ ์ด์ƒ ์žˆ์œผ๋ฉด ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.
            	
            	- ๋ชจ๋ธ.objects.filter(title="hello") : ๊ด„ํ˜ธ์•ˆ์— ์กฐ๊ฑด๊ณผ ์ผ์น˜ํ•˜๋Š” ๋ชจ๋“  ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ด ex) title="hello", ์ธ ๋ชจ๋“  ๊ฐ์ฒด ๊ฐ€์ ธ์˜ด
            	
            	- ๋ชจ๋ธ ๊ฐ์ฒด.delete() : ํ•ด๋‹น ๋ชจ๋ธ ๊ฐ์ฒด ์‚ญ์ œ
            	
            	- ๋ชจ๋ธ๊ฐ์ฒด = ๋ชจ๋ธ์ด๋ฆ„(์—ด์š”์†Œ=๋‚ด์šฉ,์—ด์š”์†Œ2=๋‚ด์šฉ2) : ๋ชจ๋ธ ๊ฐ์ฒด ์ƒ์„ฑ
            	
            	- > ๋ชจ๋ธ ๊ฐ์ฒด ์ƒ์„ฑ 2
            	- ```python
            	  ๋ชจ๋ธ๊ฐ์ฒด = ๋ชจ๋ธ์ด๋ฆ„()
            	  ๋ชจ๋ธ๊ฐ์ฒด.์—ด์š”์†Œ1 = ๋‚ด์šฉ
            	  ๋ชจ๋ธ๊ฒ์ฒด.์—ด์š”์†Œ2 = ๋‚ด์šฉ
            	  ๋ชจ๋ธ๊ฐ์ฒด.save() # ๋ชจ๋ธ ๊ฐ์ฒด ์ ์šฉ
            	  
            
            - ์ด ๋ฐฉ๋ฒ•์œผ๋กœ ๋ชจ๋ธ๊ฐ์ฒด ์ƒ์„ฑ์„ ๋‹ค๋ฅธ ํƒ€์ด๋ฐ์— ํ•  ์ˆ˜ ์žˆ๋‹ค. > index.html (์•ฑ ๋‚ด๋ถ€ templates ํด๋” ๋‚ด๋ถ€) ```html &#123;&#37; extends &#39;base.html&#39; &#37;&#125; &#38;#60;!--base.html์˜ ํ…œํ”Œ๋ฆฟ์„ ๊ฐ€์ ธ์˜ด--&#38;#62; &#123;&#37; block body &#37;&#125;	&#38;#60;!-- base.html์˜ ๊ตฌ๋ฉ์„ ์„ ํƒ--&#38;#62;
            &#123;&#37; for todo in todos &#37;&#125; &#38;#60;!-- DTL for๋ฌธ ๊ตฌ๋ฌธ--&#38;#62;
            ์ œ๋ชฉ : &#38;#60;h1&#38;#62;todo.title&#38;#60;/h1&#38;#62; &#38;#60;!-- ๊ฐ todo ๊ฐ์ฒด์˜ ๋‚ด์šฉ๋ฌผ ๋ณด์—ฌ์ฃผ๊ธฐ--&#38;#62;
            ๋‚ด์šฉ : &#38;#60;h2&#38;#62;todo.content&#38;#60;/h2&#38;#62;
            ๋‚ ์งœ : &#38;#60;h3&#38;#62;todo.due_date&#38;#60;/h3&#38;#62;
            ์ฒดํฌ : &#38;#60;h3&#38;#62;todo.check&#38;#60;/h3&#38;#62;
            &#123;&#37; endfor &#37;&#125;&#38;#60;!-- for๋ฌธ, ๊ผญ ๋์„ ์•Œ๋ฆด๊ฒƒ --&#38;#62; &#123;&#37; endblock &#37;&#125; &#38;#60;!-- block์˜ ๋ --&#38;#62;
            
            ## Django Create ์ƒ์„ฑ
            1. ์•ฑ์˜ urls.py์˜ urlpatterns ๋ฆฌ์ŠคํŠธ์— url์ด๋ฆ„, views์˜ ํ•จ์ˆ˜, url ๋ณ€์ˆ˜๋ช…์„ ํ• ๋‹นํ•ด ๋„ฃ๋Š”๋‹ค.
            > ์•ฑ ํด๋” ๋‚ด๋ถ€์˜ urls.py์˜ urlpatterns ์˜ˆ์‹œ
            ```python
            urlpatterns = [
                path(&#39;create/&#39;, views.create, name=&#34;create&#34;),
                #๋’ค์˜ name์€ namespacing์œผ๋กœ, url๋Œ€์‹  ์“ธ ์ด๋ฆ„
                # ๊ธฐํƒ€ ํ•„์š”ํ•œ path ์ถ”๊ฐ€
            ]
            
            
            1. ํ•ด๋‹น ์•ฑ ํด๋” ๋‚ด๋ถ€์— views.py ํŒŒ์ผ๋กœ ๊ฐ€์„œ ์œ„ pathํ•จ์ˆ˜์˜ 2๋ฒˆ์งธ ์ธ์ž์ธ ํ•จ์ˆ˜๋ช…์„ ๋งŒ๋“ ๋‹ค. (์ผ๋ฐ˜์ ์œผ๋กœ url ์ด๋ฆ„๊ณผ ๊ฐ™๋‹ค.)

              ์•ฑ ํด๋” ๋‚ด๋ถ€์˜ views.py์˜ create ํ•จ์ˆ˜ ์˜ˆ์‹œ
              ```python
              from django.shortcuts import render, redirect # redirect์™€ render๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ์ž„ํฌํŠธ ํ•ด์•ผํ•œ๋‹ค.
              from .models import TODO # ์‚ฌ์šฉํ•  ๋ชจ๋ธ ๋˜ํ•œ ๋ถˆ๋Ÿฌ์™€์•ผํ•จ

            def create(request):
            if request.method == "POST": # ๋งŒ์•ฝ form์˜ method๊ฐ€ Post์ธ์ฑ„๋กœ ๋ณด๋‚ด์ง€๋ฉด?
            # ๊ทธ๋ ‡๋‹ค๋ฉด ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๊ณ  ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์˜ฌ๋ฆฌ๊ณ  ๋ฉ”์ธ ํŽ˜์ด์ง€๋กœ ๋Œ๋ ค๋ณด๋ƒ„
            check = request.POST.get('check') # check ๋˜๋ฉด 'on'์„ ๋ฆฌํ„ดํ•จ
            if check == 'on':
            check = True
            else:
            check = False
            title = request.POST.get('title')
            content = request.POST.get('content')
            due_date = request.POST.get('due-date')
            # todo = TODO()
            # todo.check = check
            # todo.title = title
            # todo.content = content
            # todo.due_date = due_date
            # todo.save() # ๋˜‘๊ฐ™์€ ๊ธฐ๋Šฅ์„ ํ•˜๋Š” ์ฝ”๋“œ
            # ๋” ๊ธธ์ง€๋งŒ ๋Œ€์‹  save()๋ฅผ ์ด์šฉํ•ด todo ๊ฐ์ฒด์˜ ์ƒ์„ฑ ํƒ€์ด๋ฐ์„ ์›ํ•˜๋Š” ์‹œ๊ฐ„์— ํ•  ์ˆ˜ ์žˆ์Œ
            todo = TODO.objects.create(check=check, title=title, content=content, due_date=due_date)
            return redirect('CRUD:index') # /์žˆ์œผ๋ฉด ๋ฃจํŠธ์ฃผ์†Œ์— ์ถ”๊ฐ€, ์—†์œผ๋ฉด ํ˜„์žฌ ์ฃผ์†Œ ์•ž์— ์ถ”๊ฐ€
            else: # form์˜ method๊ฐ€ Get์ด๋ผ๋ฉด?
            # ๊ทธ๋ ‡๋‹ค๋ฉด todo ์ •๋ณด๋ฅผ ์ž…๋ ฅํ•˜๋Š” ํŽ˜์ด์ง€๋กœ ๋ณด๋‚ด์•ผํ•จ
            return render(request, 'create.html')

            - ๊ธฐ๋ณธ ์ •๋ณด method๋Š” GET๋ฐฉ์‹์ด๋‹ค. ์‚ฌ์šฉ์ž๊ฐ€ ์ƒˆ๋กœ์šด ๊ธ€์„ ์“ฐ๊ธฐ ์œ„ํ•ด create url๋กœ ๋“ค์–ด์˜ค๋ฉด GET๋ฐฉ์‹์ด๋ฏ€๋กœ crete.html์ด ๋งŒ๋“œ๋Š” ํŽ˜์ด์ง€๋กœ ๊ฐ€์„œ ์ •๋ณด ์ž…๋ ฅ์ฐฝ์œผ๋กœ ๊ฐ„๋‹ค.
            - ์ •๋ณด๋ฅผ ๋ชจ๋‘ ์ž…๋ ฅํ•˜๊ณ  ์‚ฌ์šฉ์ž๊ฐ€ method๋ฅผ POST ๋ฐฉ์‹์œผ๋กœ ์„ค์ •ํ•œ ํผ์—์„œ submit ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด, POST ๋ฐฉ์‹์œผ๋กœ ์ •๋ณด๊ฐ€ ๋“ค์–ด์˜ค๋ฏ€๋กœ TODO ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค๊ณ  ๋ฉ”์ธํŽ˜์ด์ง€๋กœ ๋Œ์•„๊ฐ„๋‹ค.
            - ์ด๋Ÿฐ ์‹์œผ๋กœ ํ•˜๋‚˜์˜ url ์ฃผ์†Œ์—์„œ ๋ฐ›์€ ์ •๋ณด ์œ ํ˜•์— ๋”ฐ๋ผ ๋‹ค๋ฅด๊ฒŒ ๋™์ž‘ํ•˜๊ฒŒ ๋งŒ๋“ค์–ด ํšจ์œจ์ ์ธ ์›น ์ฝ”๋”ฉ์„ ๊ตฌํ˜„ํ•œ ๊ฒƒ์ด restfullํ•œ ์›น ์ฝ”๋”ฉ์ด๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.
            - ๋‹ค๋ฅธ ํ”„๋ ˆ์ž„์›Œํฌ๋Š” delete์™€ put ํ˜•์‹์˜ method๋„ ์ง€์›ํ•˜๋‚˜ django์™€ HTML5๋Š” ๊ณต์‹์ ์œผ๋กœ ์ง€์›ํ•˜์ง€ ์•Š๊ณ  ์žˆ๋‹ค. ์ด์™ธ์— ์ธ๊ธฐ์žˆ๋Š” http verb ๋ผ๋Š” ๊ฐœ๋…๋„ ์ง€์›์•ˆํ•จ
            - HTML5๋„ ๊ณต์‹์ ์œผ๋กœ ์ง€์›ํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ delete์™€ putํ˜•์‹์œผ๋กœ ๋ณด๋‚ผ ๋•Œ๋Š” ์ƒˆ๋กœ input ํƒœ๊ทธ๋ฅผ ๋งŒ๋“ค์–ด, type= hidden์—  name='_method', value="DELETE" ๋กœ ์ˆจ๊ฒจ์„œ ๋ณด๋ƒ„
            3. templates ํด๋”์— create.html์„ ๋งŒ๋“ ๋‹ค.
            > create.html ์˜ˆ์‹œ
            ```html
            &#123;&#37; extends &#39;base.html&#39; &#37;&#125;
            
            &#123;&#37; block body &#37;&#125;
            &#38;#60;form action=&#34;&#123;&#37; url &#39;CRUD:create&#39; &#37;&#125;&#34; method=&#34;POST&#34;&#38;#62; # ๋Œ€์†Œ๋ฌธ์ž ๊ตฌ๋ณ„์•ˆํ•จ
              &#123;&#37; csrf_token &#37;&#125; # ํผ ๋‚ด๋ถ€์— ์ด๊ฒŒ ์žˆ์–ด์•ผ์ง€ ์ธ์ฆ์ด๋˜์„œ ์—๋Ÿฌ ์•ˆ๋‚จ
              ๋‹ฌ์„ฑ์—ฌ๋ถ€ : &#38;#60;input type=&#34;checkbox&#34; name=&#34;check&#34;&#38;#62; # checkํ•˜๋ฉด &#39;on&#39;์„ ๋ณด๋ƒ„
              ์ œ๋ชฉ : &#38;#60;input type=&#34;text&#34; name=&#34;title&#34;&#38;#62; # ๊ฐ์ž ๋ชจ๋ธ ์ •๋ณด๋ช…์œผ๋กœ ๋ณด๋ƒ„
              ๋‚ด์šฉ : &#38;#60;input type=&#34;text&#34; name=&#34;content&#34;&#38;#62;
              ๋งˆ๊ฐ์ผ : &#38;#60;input type=&#34;date&#34; name=&#34;due-date&#34;&#38;#62;
              &#38;#60;input type=&#34;submit&#34; value=&#34;์ €์žฅ&#34;&#38;#62;
            &#38;#60;/form&#38;#62;
            &#123;&#37; endblock &#37;&#125;
            
            
            • form์˜ action ์š”์†Œ๋ฅผ DTL ๋ฌธ๋ฒ•์œผ๋กœ namespacing์„ ์ด์šฉํ•˜์—ฌ ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋‹ค.
            • โ€{% url โ€˜์•ฑ์ด๋ฆ„:url๋ณ€์ˆ˜๋ช…โ€™ ๋งค๊ฐœ๋ณ€์ˆ˜1, ๋งค๊ฐœ๋ณ€์ˆ˜2, โ€ฆ%}โ€ ๋งค๊ฐœ๋ณ€์ˆ˜ ๋˜ํ•œ ๋ณด๋‚ผ ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์•ฑ์ด๋ฆ„์„ ์„ค์ •ํ•˜์ง€ ์•Š์œผ๋ฉด โ€˜์•ฑ์ด๋ฆ„:โ€™๋ถ€๋ถ„์€ ๋นผ๋„ ๋œ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด ๋‹ค๋ฅธ ์•ฑ์— ๊ฒน์น˜๋Š” url ๋ณ€์ˆ˜๋ช…์ด ์„œ๋กœ ์ถฉ๋Œํ•  ์ˆ˜ ์žˆ๋‹ค.
            • POST ๋ฐฉ์‹์œผ๋กœ ๋ณด๋‚ด๋ฉด url ์ฃผ์†Œ์— ์ •๋ณด ๊ฐ’์ด ๋ณด์ด์งˆ ์•Š๊ณ , csrf๋กœ ์•”ํ˜ธํ™”๋˜์„œ ๋ณด๋‚ด์ง€๋ฉฐ, ์ด๋ฅผ ์ œ๋Œ€๋กœ ํ•ด๋…ํ•ด์„œ ๋ฐ›์œผ๋ ค๋ฉด form ํƒœ๊ทธ ๋‚ด๋ถ€์— {% csrf_token %}์„ ์ง€์ •ํ•˜์—ฌ ํ† ํฐ๋„ ๊ฐ™์ด ๋ณด๋‚ด์•ผ ํ•œ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด restfull ํ•œ ์›น ์ฝ”๋”ฉ๋„ ๊ฐ€๋Šฅํ•˜๋‹ค.

              Django Read(detail) ์ƒ์„ฑ

              1. ๋จผ์ € ์•ฑ ํด๋” ๋‚ด๋ถ€์˜ urlpatterns ๋ฆฌ์ŠคํŠธ์— ์ƒˆ๋กœ path๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.

                ์ƒˆ๋กœ ์ถ”๊ฐ€ํ•œ detail path
                ```python
                path('&#60;int:id&#62;/', views.detail, name="detail"), # ์ž์„ธํžˆ ๋ณผ id๋ฅผ variable routing ํ•ด์•ผํ•จ

            2. views.py์— detail ํ•จ์ˆ˜๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.
            > ์ƒˆ๋กœ ์ถ”๊ฐ€ํ•œ detail ํ•จ์ˆ˜
            ```python
            def detail(request, id): #์ž์„ธํžˆ ๋ณผ todo์˜ id๋ฅผ htmlํŒŒ์ผ๋กœ ๋„˜๊ฒจ์ฃผ์–ด์•ผ ํ•œ๋‹ค.
                todo = TODO.objects.get(id=id) # ํ•ด๋‹น id์ธ TODO ๊ฐ์ฒด ์ฐพ๊ธฐ
                context = &#123; # render๋กœ ๋„˜๊ฒจ์ค„ ๋•Œ 3๋ฒˆ์งธ ์ธ์ž๋กœ, ๋”•์…”๋„ˆ๋ฆฌ ํ˜•ํƒœ๋กœ ๋„˜๊ฒจ์ค˜์•ผํ•œ๋‹ค.
                    &#39;todo&#39;: todo,
                &#125;
                return render(request, &#39;detail.html&#39;, context)
            
            
            1. deatil.html ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด templates ํด๋”์— ์ถ”๊ฐ€ํ•œ๋‹ค.

              detail.html
              ```python
              {% extends 'base.html' %}
              {% block body %}
              &#60;h1&#62;{{todo.title}}&#60;/h1&#62;
              &#60;h2&#62;{{todo.content}}&#60;/h2&#62;
              &#60;h3&#62;{{todo.due_date}}&#60;/h3&#62;
              &#60;h3&#62;{{todo.check}}&#60;/h3&#62;
              &#60;a href=""&#62;์‚ญ์ œ&#60;/a&#62;
              &#60;a href=""&#62;์ˆ˜์ •&#60;/a&#62;
              &#60;a href="{% url 'CRUD:index' %}"&#62;๋’ค๋กœ&#60;/a&#62;
              {% endblock %}

            - ๋ฉ”์ธ ํŽ˜์ด์ง€๋กœ ๋Œ์•„๊ฐ€๋‚˜๋Š” ๋’ค๋กœ์™€ ๋‚˜์ค‘์— ์ถ”๊ฐ€๋  ์‚ญ์ œ์™€ ์ˆ˜์ • ๋ฒ„ํŠผ์„ ๋„ฃ์—ˆ๋‹ค.
            4. ๊ธฐ์กด์— ์žˆ๋˜ index.html์— ํ•ด๋‹น ๋ชจ๋ธ ๊ฐ์ฒด์˜ detail ํŽ˜์ด์ง€๋กœ ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ๋งํฌ๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.
            > index.html ์˜ ์ผ๋ถ€
            ```html
            &#38;#60;a href=&#34;&#123;&#37; url &#39;CRUD:detail&#39; todo.id &#37;&#125;&#34;&#38;#62;์ž์„ธํžˆ&#38;#60;/a&#38;#62;
            
            
            • namspacing์„ ์ด์šฉํ•œ url ํ• ๋‹น์— todo์˜ id๋ฅผ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ณด๋‚ด๊ณ  ์žˆ๋‹ค.
            • ๋ณด๋‚ด์•ผ๋  ๋ณ€์ˆ˜๊ฐ€ 2๊ฐœ ์ด์ƒ์ด๋ฉด ์•ž์—์„œ ๋ถ€ํ„ฐ ์ฐจ๋ก€๋Œ€๋กœ ์ ์šฉ.

              Django Update ์ƒ์„ฑ

              1. ์•ฑ ํด๋” ๋‚ด๋ถ€์˜ urls.py์˜ urlpatterns ๋ฆฌ์ŠคํŠธ์— update path๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.

                url.py์˜ ์ผ๋ถ€
                ```python
                path('&#60;int:id&#62;/update/', views.update, name="update"),

            2. ์•ฑ ํด๋” ๋‚ด๋ถ€์˜ views.py์— update ํ•จ์ˆ˜๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.
            > views.py์˜ update ํ•จ์ˆ˜
            ```python
            def update(request, id):
                todo = TODO.objects.get(id=id) # get์ผ ๋•Œ๋„, post์ผ ๋•Œ๋„ todo๋ฅผ ์“ฐ๋ฏ€๋กœ ์™ธ๋ถ€์—์„œ ๊ตฌํ•œ๋‹ค.
                if request.method == &#34;POST&#34;:        
                    todo.check = request.POST.get(&#39;check&#39;)
                    if todo.check == &#39;on&#39;:
                        todo.check = True
                    else:
                        todo.check = False
                    todo.title = request.POST.get(&#39;title&#39;)
                    todo.content = request.POST.get(&#39;content&#39;)
                    todo.due_date = request.POST.get(&#39;due-date&#39;)
                    return redirect(&#39;CRUD:index&#39;) # ๊ฐ’์„ ์ˆ˜์ •ํ•˜๊ณ  ๋ฉ”์ธ ํŽ˜์ด์ง€๋กœ
                else:
                    context = &#123;
                    &#34;todo&#34;: todo,
                    &#125;
                    return render(request, &#39;update.html&#39;, context)
            
            
            1. update.html ํŒŒ์ผ์„ templates ํด๋” ์•ˆ์— ์ถ”๊ฐ€ํ•œ๋‹ค.

              update.html
              ```html
              {% extends 'base.html' %}
              {% block body %}
              &#60;form action="{% url 'CRUD:update' %}" method="POST"&#62;
              {% csrf_token %}
              ๋‹ฌ์„ฑ์—ฌ๋ถ€ : &#60;input type="checkbox" name="check"&#62;
              ์ œ๋ชฉ : &#60;input type="text" name="title" value="{{todo.title}}"&#62;
              ๋‚ด์šฉ : &#60;input type="text" name="content" value="{{todo.content}}"&#62;
              ๋งˆ๊ฐ์ผ : &#60;input type="date" name="due-date" value="{{todo.due_date}}"&#62;
              &#60;input type="submit" value="์ €์žฅ"&#62;
              &#60;/form&#62;
              {% endblock %}

            ## Django Delete ์ƒ์„ฑ
            
            ## bootstrap ๊พธ๋ฏธ๊ธฐ
            
            ## git
            1. gitignore.io์— ๊ฐ€์„œ ์ž์‹ ์˜ ํ™˜๊ฒฝ์„ ์ž…๋ ฅํ•œ ๋’ค ๊นƒํ—™์— ์˜ฌ๋ฆฌ์ง€ ์•Š์„ ์„ค์ •์„ ๋ฐ›์•„ .gitignore์— ๋„ฃ๊ธฐ
            2. github์— ๊ฐ€์„œ ์ƒˆ๋กœ์šด ๋ ˆํฌ์ง€ํ† ๋ฆฌ ๋งŒ๋“ค๊ธฐ
            3. ํ•ด๋‹น ํด๋”์— ๊ฐ€์„œ ํ„ฐ๋ฏธ๋„ ์•ˆ์—  git init์œผ๋กœ git ํ™˜๊ฒฝ์œผ๋กœ ๋งŒ๋“  ๋’ค, 
            4. ํ„ฐ๋ฏธ๋„์— git commit -m "message"๋กœ ์ฒซ ์ปค๋ฐ‹ ๋‚จ๊ธฐ๊ธฐ
            5. ํ„ฐ๋ฏธ๋„์— git remote add origin ๋ ˆํฌ์ง€ํ† ๋ฆฌ์ฃผ์†Œ๋กœ ์—ฐ๊ฒฐํ•˜๊ธฐ
            6. git push origin master๋กœ ํ˜„์žฌ ์ƒํƒœ ์—…๋กœ๋“œํ•˜๊ธฐ
            7. git add ., git commit -m "message", git push origin master๋กœ ์—…๋ฐ์ดํŠธ, ์ปค๋ฐ‹ ๋‚จ๊ธฐ๊ธฐ
            
            ## admin ์ƒ์„ฑํ•˜๊ธฐ, ๋กœ๊ทธ์ธ ํ•˜๊ธฐ
            1. ํ„ฐ๋ฏธ๋„์— python manage.py createsuperuser ์ž…๋ ฅ
            2. ํ„ฐ๋ฏธ๋„์— ์œ ์ €๋„ค์ž„, ์ด๋ฉ”์ผ์ฃผ์†Œ, ํŒจ์Šค์›Œ๋“œ ์ž…๋ ฅ, ํŒจ์Šค์›Œ๋“œ ํ™•์ธ์„ ๋ฌผ์–ด๋ด„
            	- ํŒจ์Šค์›Œ๋“œ ์ž…๋ ฅ์‹œ ์ž…๋ ฅ๊ฒฐ๊ณผ๊ฐ€ ๋ˆˆ์— ๋ณด์ด์ง€ ์•Š๋Š”๋‹ค.
            2. http://์„œ๋ฒ„์ฃผ์†Œ/admin ์— ๋“ค์–ด๊ฐ€์„œ ๋กœ๊ทธ์ธํ•˜๋ฉด ๊ด€๋ฆฌ์ž ํŽ˜์ด์ง€๋กœ ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ๋‹ค.
            3. ํ•ด๋‹น ์•ฑ ํด๋” ๋‚ด๋ถ€์˜ admin.py์—์„œ admin.site.register(๋Œ€์ƒ ๋ชจ๋ธ)๋กœ ๋Œ€์ƒ ๋ชจ๋ธ์„ ์—…๋ฐ์ดํŠธํ•˜๋ฉด ๊ด€๋ฆฌ ํŽ˜์ด์ง€๋กœ ๋“ค์–ด๊ฐ€๋ฉด ๋ณผ ์ˆ˜ ์žˆ๋‹ค.
            	- ๊ทธ ์ „์— from .models import ๋ชจ๋ธ์ด๋ฆ„ ์œผ๋กœ ๋ถˆ๋Ÿฌ์˜จ๋‹ค.
            ## ๋Œ“๊ธ€ ๋‹ฌ๊ธฐ ๊ธฐ๋Šฅ
            ### django ORM
            #### READ
            > ๊ฒŒ์‹œ๋ฌผ ๊ฐ€์ ธ์˜ค๋Š” ๋ฒ•
            ```python
            Question.objects.get(id=1)
            
            
            • ์—†๋Š” id๋ฉด ์—๋Ÿฌ ๋ฐœ์ƒ

              ๊ฒŒ์‹œ๋ฌผ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
              ```python
              In [6]: question = Question.objects.get(id=1)

            In [7]: question
            Out[7]: &#60;Question: Question object (1)&#62;

            - ๊ฒŒ์‹œ๋ฌผ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
            > ๋Œ“๊ธ€ ์ €์žฅํ•˜๊ธฐ
            ```python
            In [7]: question
            Out[7]: &#38;#60;Question: Question object (1)&#38;#62;
            
            In [8]: Answer
            Out[8]: questions.models.Answer
            
            In [9]: answer = Answer()
            
            In [10]: answer
            Out[10]: &#38;#60;Answer: Answer object (None)&#38;#62; # ์•„์ง ์ •๋ณด๊ฐ€ ์—†์œผ๋ฏ€๋กœ None
            
            In [11]: answer.content
            Out[11]: &#39;&#39;
            
            In [12]: answer.content = &#34;์ด๊ฒƒ์€ ๋Œ“๊ธ€์ž…๋‹ˆ๋‹ค.&#34;
            
            In [13]: answer.content
            Out[13]: &#39;์ด๊ฒƒ์€ ๋Œ“๊ธ€์ž…๋‹ˆ๋‹ค.&#39;
            
            In [14]: answer.question = question
            
            In [15]: answer.question
            Out[15]: &#38;#60;Question: Question object (1)&#38;#62;
            
            In [16]: answer.save() # ์ •๋ณด ๋‹ค ์•ˆ์ฑ„์šด์ฑ„๋กœ ํ•˜๋ฉด ์—๋Ÿฌ ๋ฐœ์ƒ
            
            In [17]: answer
            Out[17]: &#38;#60;Answer: Answer object (1)&#38;#62;
            
            In [18]: Answer.objects.create(content=&#34;๋‘๋ฒˆ์งธ ๋Œ“๊ธ€&#34;, question=question)
            Out[18]: &#38;#60;Answer: Answer object (2)&#38;#62;
            
            

            ๋Œ“๊ธ€ ์ •๋ณด

            In [19]: answer.id
            Out[19]: 1
            
            In [20]: answer.pk
            Out[20]: 1
            
            In [21]: answer.question_id # answer๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” id๊ฐ’, **์ด๊ฒŒ ๋” ๋น ๋ฆ„**
            Out[21]: 1
            
            In [23]: answer.question.id # answer๊ฐ€ ๊ฐ€์ง€๊ณ ์žˆ๋Š” question์ด ๊ฐ€์ง€๊ณ  ์žˆ๋Š” id๊ฐ’
            Out[23]: 1
            
            
            • answer.id == answer.pk(primary key) ์•„์ด๋””๋ž‘ ๊ฐ™์Œ
            • question_id์™€ answer.question.id ๊ฐ’์€ ๊ฐ™์ง€๋งŒ ์ ‘๊ทผํ•˜๋Š”๋ฐ question์„ ์ฐพ์ง€ ์•Š์œผ๋ฏ€๋กœ question_id๊ฐ€ ๋”์šฑ ๋น ๋ฅด๋‹ค.
              ```python
              In [26]: answer.question.content
              Out[26]: 'worst mankind on the planet earth'

            In [27]: question.answer_set # foreignkey๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” answer์— ์˜ํ•ด ์ž๋™์œผ๋กœ ์ƒ์„ฑ๋œ question์˜ ์š”์†Œ
            Out[27]: &#60;django.db.models.fields.related_descriptors.create_reverse_many_to_one_manager.&#60;locals&#62;.RelatedManager at 0x28b04474808&#62;

            In [28]: question.answer_set.all()
            Out[28]: &#60;QuerySet [&#60;Answer: Answer object (1)&#62;, &#60;Answer: Answer object (2)&#62;]&#62; # answer ๊ฐ์ฒด๊ฐ€ 2๊ฐœ ๋“ค์–ด์žˆ๊ณ  ์ด์— ์ ‘๊ทผ ๊ฐ€๋Šฅ

            - answer๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” question์˜ ๋‚ด์šฉ์— ์ ‘๊ทผ ๊ฐ€๋Šฅ
            
            #### 1:N
            > Question(1)=>Answer(N) : answer_set ์œผ๋กœ ์ ‘๊ทผ ๊ฐ€๋Šฅ
            ```python
            In [28]: question.answer_set.all()
            Out[28]: &#38;#60;QuerySet [&#38;#60;Answer: Answer object (1)&#38;#62;, &#38;#60;Answer: Answer object (2)&#38;#62;]&#38;#62;
            
            
            • question.answer ๋กœ๋Š” ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์—†๋‹ค. (1๊ฐœ์—ฌ๋„)
            • ํ•ญ์ƒ ๋ฐ์ดํ„ฐ๊ฐ€ ์—ฌ๋Ÿฌ๊ฐœ๋ผ๊ณ  ์ƒ๊ฐํ•ด์•ผํ•œ๋‹ค.
            • question์—๋Š” answer์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๋„ฃ์ง€ ์•Š๋Š”๋‹ค.(์—†์„ ์ˆ˜๋„ ์žˆ์œผ๋ฏ€๋กœ) dir(๊ฐ์ฒด)๋กœ ํ™•์ธ ๊ฐ€๋Šฅ

              Answer(N)=>Question(1): question ์œผ๋กœ ์ ‘๊ทผ ๊ฐ€๋Šฅ
              ```python
              In [15]: answer.question
              Out[15]: &#60;Question: Question object (1)&#62;

            ```