- migrations
- 큐
- 통계학
- 백트래킹
- create
- Tree
- 뷰
- distinct
- outer join
- count
- 트리
- 그리디
- regexp
- Django
- stack
- N:1
- Article & User
- DB
- SQL
- drf
- update
- 이진트리
- 스택
- ORM
- 쟝고
- Queue
- M:N
- Vue
- 완전검색
- delete
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
목록분류 전체보기 (421)
데이터 분석 기술 블로그
API (Apllication Programming Interface)애플리케이션과 프로그래밍으로 소통하는 방법을 말합니다.클라이언트 - 서버처럼 서로 다른 프로그램에서 요청과 응답을 받을 수 있도록 만든 체계입니다.REST (Representaional State Transfer)API Server를 개발하기 위한 일종의 소프트웨어 설계 방법론으로 약속이지 규칙은 아닙니다.REST APIREST라는 설계 디자인 약속을 지켜 구현한 API입니다.REST에서 자원을 정의하고 주소를 지정하는 방법자원의 식별URI자원의 행위HTTP Methods자원의 표현JSON 데이터궁극적으로 표현되는 데이터 결과물
문제 상황prefetch_related 적용문제 해결 1단계입니다.게시글을 조회하면서 참조된 댓글까지 한 번에 조회합니다.# views.pydef index_4(request): # articles = Article.objects.order_by('-pk') articles = Article.objects.prefetch_related('comment_set').order_by('-pk') # articles = Article.objects.prefetch_related( # Prefetch('comment_set', queryset=Comment.objects.select_related('user')) # ).order_by('-pk') "111 queries includin..
prefetch_relatedM:N 또는 N:1 역참조 관계에서 사용합니다. SQL이 아닌 Python을 사용한 JOIN을 진행합니다.문제 상황prefetch_related 적용문제를 해결해 봅니다.게시글을 조회하면서 참조된 댓글까지 한 번에 조회해서 가져옵니다.# views.pydef index_3(request): # articles = Article.objects.order_by('-pk') articles = Article.objects.prefetch_related('comment_set').order_by('-pk') context = { 'articles': articles, } return render(request, 'articles/index_3...
select_relatedSQL의 INNER JOIN 쿼리를 활용합니다. 1:1 또는 N:1 참조 관계에서 사용합니다.문제 상황select_related 적용문제를 해결해 봅니다.게시글을 조회하면서 유저 정보까지 한 번에 조회해서 가져옵니다.# views.pydef index_2(request): # articles = Article.objects.order_by('-pk') articles = Article.objects.select_related('user').order_by('-pk') context = { 'articles': articles, } return render(request, 'articles/index_2.html', context)"11 qu..
annotateSQL의 GROUP BY 쿼리를 사용합니다.문제 상황annotate 적용문제를 해결해 봅시다.게시글을 조회하면서 댓글 개수까지 한 번에 조회해서 가져옵니다.# views.pydef index_1(request): # articles = Article.objects.order_by('-pk') articles = Article.objects.annotate(Count('comment')).order_by('-pk') context = { 'articles': articles, } return render(request, 'articles/index_1.html', context)댓글 개수 : {{ article.comment__count }}"11 qu..
Improve query같은 결과를 얻기 위해 DB 측에 보내는 쿼리 개수를 점차 줄여 조회합니다.1. 사전 준비데이터게시글 10개 / 댓글 100개 / 유저 5개모델 관계N:1 - Article:User / Comment:Article / Comment:ArticleN:M - Article:Userpython manage.py migratepython manage.py laoddata users.json articles.json comments.jsonInstalled 115 object(s) from 3 fixture(s)2. 종류annotateselect_relatedprefetch_relatedselect_related & prefetch_related
1. FixturesDjango가 데이터베이스로 가져오는 방법을 알고 있는 데이터 모음입니다. 데이터베이스 구조에 맞추어 작성되어있습니다.2. 초기 데이터 제공Fixtures의 사용 목적입니다.3. Fixtures 활용3-1 사전 준비M:N까지 모두 작성된 Django 프로젝트에서 유저, 게시글, 댓글 등 각 데이터를 최소 2~3개 이상 생성해 둡니다.3-2 fixtures 관련 명령어dumpdata: 생성 (데이터 추출)loaddata: 로드 (데이터 입력)3-3 dumpdata데이터베이스의 모든 데이터를 추출합니다. 추출한 데이터는 json 형식으로 저장합니다.# 작성 예시python manage.py dumpdata [app_name[.ModelName] [app_name[.ModelName] ....
User(M) - User(N)0명 이상의 회원은 0명 이상의 회원과 관련이 있습니다. 즉, 회원은 0명 이상의 팔로워를 가질 수 있고, 0명 이상의 다른 회원들을 팔로잉할 수 있습니다.ManyToManyFiled를 작성합니다.참조 : 내가 팔로우하는 사람들(팔로잉, followings)역참조 : 상대방 이밪에서 나는 팔로워 중 한 명 (팔로워, followers)바뀌어도 상관 없으나 관계 조회 시 생각하기 편한 방향으로 정한 것입니다.# accounts/models.pyclass User(AbstractUser): followings = models.ManyToManyField('self', symmetraicl=False, related_name='followers')Migrations 진행 후..