django_extensions 모듈 활용하기
django_extensions 모듈 설치하기
pipenv install django_extensions --dev
shell_plus 사용하기
python manage.py shell_plus --print-sql
을 통해 쉘에 접속한다.Post.objects.all()
을 통해 쿼리를 수행한다.- 쿼리 결과 뿐만 아니라 수행 시간과 쿼리 내용까지 출력된다.
python manage.py shell_plus --print-sql
# Shell Plus Model Imports
from django.contrib.admin.models import LogEntry
from django.contrib.auth.models import Group, Permission, User
from django.contrib.contenttypes.models import ContentType
from django.contrib.sessions.models import Session
from instagram.models import Post
# Shell Plus Django Imports
from django.core.cache import cache
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import transaction
from django.db.models import Avg, Case, Count, F, Max, Min, Prefetch, Q, Sum, When
from django.utils import timezone
from django.urls import reverse
from django.db.models import Exists, OuterRef, Subquery
Python 3.8.11 (default, Aug 8 2021, 20:23:04)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.29.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: Post.objects.all
Out[1]: <bound method BaseManager.all of <django.db.models.manager.Manager object at 0x10f994dc0>>
In [2]: Post.objects.all()
Out[2]: SELECT VERSION(), @@sql_mode, @@default_storage_engine, @@sql_auto_is_null, @@lower_case_table_names,
CONVERT_TZ('2001-01-01 01:00:00', 'UTC', 'UTC') IS NOT NULL
Execution time: 0.003324s [Database: default]
SET
SESSION
TRANSACTION
ISOLATION LEVEL READ COMMITTED
Execution time: 0.002954s [Database: default]
SELECT `instagram_post`.`id`,
`instagram_post`.`message`,
`instagram_post`.`is_publish`,
`instagram_post`.`photo`,
`instagram_post`.`created_at`,
`instagram_post`.`updated_at`
FROM `instagram_post`
ORDER BY `instagram_post`.`id` DESC
LIMIT 21
Execution time: 0.004925s [Database: default]
<QuerySet [<Post: testclean_message>, <Post: test>, <Post: 세번째 메시지clean_message>, <Post: 두번째 메시지>, <Post: 첫번째 메시지>]>
Author And Source
이 문제에 관하여(django_extensions 모듈 활용하기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@joje/djangoextensions-모듈-활용하기저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)