This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from django.contrib.auth.models import User | |
from django.db import models | |
class Company(models.Model): | |
name: str = models.CharField(max_length=128, null=False) | |
tel_num: str = models.CharField(max_length=128, null=False) | |
address: str = models.CharField(max_length=128, null=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app_name.management.commands.bulk_create.py를 만들고 이 내용을 bulk_create.py에 복붙하세요 | |
from random import randint | |
from django.core.management import BaseCommand | |
from django.contrib.auth.hashers import make_password | |
from django.contrib.auth.models import User | |
from django.utils import timezone |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python manage.py bulk_create --user_cnt 300 --company_cnt 100 --product_cnt 1000 --order_cnt 10000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT *, | |
(select "descriptions" | |
from orm_practice_app_order | |
where "orm_practice_app_orderedproduct"."related_order_id" = "orm_practice_app_order"."id" | |
AND "descriptions" = '주문의 상세내용입니다...1') as descriptions | |
FROM "orm_practice_app_orderedproduct" | |
WHERE "orm_practice_app_orderedproduct"."id" = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(Model.objects | |
.filter(조건절) | |
.select_related('정방향_참조_필드') # 해당 필드를 join해서 가져온다. | |
.prefetch_related('역방향_참조_필드') # 해당 필드는 추가쿼리로 가져온다. | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select * from 'Model' m | |
(inner OR left outer) join '정방향_참조_필드' r on m.r_id=r.id | |
'where '조건절'; | |
select * from '역방향_참조_필드' where id in ('첫번째 쿼리 결과의 id 리스트'); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT `orm_practice_app_company`.`id`, | |
`orm_practice_app_company`.`name`, | |
`orm_practice_app_company`.`tel_num`, | |
`orm_practice_app_company`.`address` | |
FROM `orm_practice_app_company` | |
WHERE `orm_practice_app_company`.`name` = 'company_name1'; | |
SELECT "orm_practice_app_product"."id", "orm_practice_app_product"."name", "orm_practice_app_product"."price", "orm_practice_app_product"."product_owned_company_id" | |
FROM "orm_practice_app_product" |
OlderNewer