django-extensions

dingdong·2022년 1월 13일
0

django-extensions

https://django-extensions.readthedocs.io/en/latest/

설치방법

$ pip install django-extensions

사용법

1) django 프로젝트의 settings.py
INSTALLED_APPS 에 'django_extensions' 추가


INSTALLED_APPS = [
    ...
    'django_extensions',

]

2) python manage.py shell_plus --print-sql 실행

  • 사용할 Class, Fcuntion 을 자동으로 import 시켜줌
    • 단, from 위치는 다르더라도 import 시킬 Class 가 중복이 되면 Overwirte 되서, 따로 Import 시켜줘야됨.
  • 실행할때 SQL 문이 출력됨

(venv) # python manage.py shell_plus --print-sql
 
# Shell Plus Model Imports
from instagram.models import Post
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
# 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.10 (default, Nov 26 2021, 20:14:08)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>>
>>>
>>> Post.objects.all()
SELECT "instagram_post"."id",
       "instagram_post"."message",
       "instagram_post"."photo",
       "instagram_post"."is_public",
       "instagram_post"."created_at",
       "instagram_post"."updated_at"
  FROM "instagram_post"
 ORDER BY "instagram_post"."id" DESC
 LIMIT 21
Execution time: 0.001612s [Database: default]
<QuerySet [<Post: 세번째 메세지>, <Post: 두번째 메세지>, <Post: 첫번째 메세지>]>
>>>
profile
자동화 개발

0개의 댓글