-
[LAFESTA] 수정사항들코딩/🟢 DJANGO 2021. 9. 13. 01:19
1. 수정전
for product in products: colors = product.colors.all() images = Image.objects.filter(product=product.id)
A. product 와 image 의 참조관계 파악하신 후에 _set의 사용법을 확인할 것.
Q. Image 객체에 접근하는 것보단 set을 이용해서 이미 불러온 product를 활용하는 것이 데이터 통신에서 효율적인가?
A. 가독성을 높이고자 하는 이유와 추후 효율적인 데이터 통신을 위해 지금과 같은 방식으로 어떠한 쿼리를 호출하는지 파악하기 위한 이유
수정 후
for product in products: colors = product.colors.all() images = product.image_set.filter(product=product.id)
훨씬 코드가 깔끔하고 어떤 것을 가져와야하는지 명확해졌다.
2. 수정 전
type_id = request.GET["typeId"] page = int(request.GET["page"])
https://stackoverflow.com/questions/150505/capturing-url-parameters-in-request-get
Capturing URL parameters in request.GET
I am currently defining regular expressions in order to capture parameters in a URL, as described in the tutorial. How do I access parameters from the URL as part the HttpRequest object? My HttpReq...
stackoverflow.com
해당 기능이 구현하지 않았을때 에러코드가 나지 않으려면
GET.get("", 기본값) 으로 설정하면 에러발생시키지 않고도 효율적인 서버 운영을 할 수 있다.
수정 후
type_id = request.GET.get("typeId", None) page = int(request.GET.get("page", 1))
'코딩 > 🟢 DJANGO' 카테고리의 다른 글
[DJANGO] 카카오 소셜로그인 구현 (0) 2021.10.03 [DJANGO] 인증과 인가(4) : Login decorator (0) 2021.09.25 [REST API] Path Prameter & Query Prameter (0) 2021.09.13 [API] REST API (0) 2021.09.12 [DJANGO] 인증과 인가 (3) : 로그인 구현 (0) 2021.08.27