WIL #8 [Django] ORM


🤷 期間:2021.04.23~2021.04.25
🤷 資料:https://www.notion.so/wecode/Django-C-R-U-D-1-e105b472f2cc4647a38305b343389de3
🤷 内容:fuck ORMとは?

ORMの概念



Data CRUD(DjangoとMySQL通信!!)







prodcuts/models.pyの作成


models.pyのロール

.
├── manage.py
├── products
│   ├── models.py 	# Model class 작성 --> database table과 mapping
│   ├── urls.py
│   └── views.py
└── westarbucks
    └── urls.py

models.例

from django.db import models


class Menu(models.Model):
		name = models.CharField(max_length=20)

	  class Meta:
          db_table = 'menus'

class Category(models.Model):
		name = models.CharField(max_length=20)
		menu = models.ForeignKey('Menu', on_delete=models.CASCADE)

    class Meta:
          db_table = 'categories'

class Product(models.Model):
		name     = models.CharField(max_length=100)
		category = models.ForeignKey('Category', on_delete=models.CASCADE)

		class Meta:
          db_table = 'products'

これまで適用するために、移行をmigrations&migrateに保存します!