포린키가있는모델클래스.objects.select_related('포린키필드명', '포린키필드명').filter(포린키가바라보든모델클래스__포린키가바라보는모델클래스의필드명=조건)
>>> ArtworkPrice.objects.select_related('artwork','device').filter(artwork__is_customed=False)
<QuerySet [<ArtworkPrice: ArtworkPrice object (2)>, <ArtworkPrice: ArtworkPrice object (3)>, <ArtworkPrice: ArtworkPrice object (4)>, <ArtworkPrice: ArtworkPrice object (5)>, <ArtworkPrice: ArtworkPrice object (6)>, <ArtworkPrice: ArtworkPrice object (7)>, <ArtworkPrice: ArtworkPrice object (8)>, <ArtworkPrice: ArtworkPrice object (9)>, <ArtworkPrice: ArtworkPrice object (10)>, <ArtworkPrice: ArtworkPrice object (11)>, <ArtworkPrice: ArtworkPrice object (12)>, <ArtworkPrice: ArtworkPrice object (13)>, <ArtworkPrice: ArtworkPrice object (14)>, <ArtworkPrice: ArtworkPrice object (15)>, <ArtworkPrice: ArtworkPrice object (16)>, <ArtworkPrice: ArtworkPrice object (17)>, <ArtworkPrice: ArtworkPrice object (18)>, <ArtworkPrice: ArtworkPrice object (19)>, <ArtworkPrice: ArtworkPrice object (20)>, <ArtworkPrice: ArtworkPrice object (21)>, '...(remaining elements truncated)...']>
>>> artwork = ArtworkPrice.objects.select_related('artwork','device').filter(artwork__is_customed=False)
>>> for i in artwork:
... print(i.price)
...
50.00
50.00
50.00
50.00
50.00
ArtworkPrice.objects.select_related('artwork','device').filter(artwork__is_customed=False)
<QuerySet [<ArtworkPrice: ArtworkPrice object (2)>, <ArtworkPrice: ArtworkPrice object (3)>, <ArtworkPrice: ArtworkPrice object (4)>, <ArtworkPrice: ArtworkPrice object (5)>, <ArtworkPrice: ArtworkPrice object (6)>, <ArtworkPrice: ArtworkPrice object (7)>, <ArtworkPrice: ArtworkPrice object (8)>, <ArtworkPrice: ArtworkPrice object (9)>, <ArtworkPrice: ArtworkPrice object (10)>, <ArtworkPrice: ArtworkPrice object (11)>, <ArtworkPrice: ArtworkPrice object (12)>, <ArtworkPrice: ArtworkPrice object (13)>, <ArtworkPrice: ArtworkPrice object (14)>, <ArtworkPrice: ArtworkPrice object (15)>, <ArtworkPrice: ArtworkPrice object (16)>, <ArtworkPrice: ArtworkPrice object (17)>, <ArtworkPrice: ArtworkPrice object (18)>, <ArtworkPrice: ArtworkPrice object (19)>, <ArtworkPrice: ArtworkPrice object (20)>, <ArtworkPrice: ArtworkPrice object (21)>, '...(remaining elements truncated)...']>
>>> artwork = ArtworkPrice.objects.select_related('artwork','device').filter(artwork__is_customed=False)
>>> for i in artwork:
print(i.price, i.artwork.id, i.artwork.artwork_type.name, i.artwork.regularartworkimage_set.filter(artwork_id=i.artwork.id)[0].image_1)
중!간!생!략!
50.00 34 Impact Case https://cdn-image02.casetify.com/usr/16401/2626401/~v96/4696941_iphone11-pro-max__color_midnight-green_16000091.png.350x350-w.m80.jpg
50.00 35 Impact Case https://cdn-image02.casetify.com/usr/9516/2769516/~v14/6149093_iphone11-pro-max__color_midnight-green_16000091.png.350x350-w.m80.jpg
50.00 36 Impact Case https://cdn-image02.casetify.com/usr/18017/1518017/~v50/4750641_iphone11-pro-max__color_midnight-green_16000091.png.350x350-w.m80.jpg
50.00 37 Impact Case https://cdn-image02.casetify.com/usr/19008/889008/~v71/4043707_iphone11-pro-max__color_midnight-green_16000091.png.350x350-w.m80.jpg
50.00 38 Impact Case https://cdn-image02.casetify.com/usr/11785/3671785/~v28/5458332_iphone11-pro-max__color_midnight-green_16000091.png.350x350-w.m80.jpg
50.00 39 Impact Case https://cdn-image02.casetify.com/usr/11962/2531962/~v66/4710907_iphone11-pro-max__color_midnight-green_16000091.png.350x350-w.m80.jpg
50.00 40 Impact Case https://cdn-image02.casetify.com/usr/28613/1288613/~v24/4271724_iphone11-pro-max__color_midnight-green_16000091.png.350x350-w.m80.jpg
50.00 41 Impact Case https://cdn-image02.casetify.com/usr/11785/3671785/~v28/5447617_iphone11-pro-max__color_midnight-green_16000091.png.350x350-w.m80.jpg
>>>
for i in artwork:
print(i.artwork.regularartworkimage_set.filter(artwork_id=i.artwork.id).values('artwork_color__name','artwork_color__info'))
중!간!생!략!
ork_color__info': 'radial-gradient(#FF7 0%, #fff 48%, pink 52%, pink 100%) '}, {'artwork_color__name': 'Pink/Blue', 'artwork_color__info': 'https://cdn-stamplib.casetify.com/cms/image/9457634f344728ab9fec8735b52590a7.png'}, {'artwork_color__name': 'Pink/Blue', 'artwork_color__info': 'https://cdn-stamplib.casetify.com/cms/image/9457634f344728ab9fec8735b52590a7.png'}, {'artwork_color__name': 'Pink/Blue', 'artwork_color__info': 'https://cdn-stamplib.casetify.com/cms/image/9457634f344728ab9fec8735b52590a7.png'}, {'artwork_color__name': 'Pink/Blue', 'artwork_color__info': 'https://cdn-stamplib.casetify.com/cms/image/9457634f344728ab9fec8735b52590a7.png'}, {'artwork_color__name': 'Neon Yellow', 'artwork_color__info': '#eaf850'}, {'artwork_color__name': 'Neon Yellow', 'artwork_color__info': '#eaf850'}, {'artwork_color__name': 'Neon Yellow', 'artwork_color__info': '#eaf850'}, {'artwork_color__name': 'Neon Yellow', 'artwork_color__info': '#eaf850'}, '...(remaining elements truncated)...']>
>>>
[Django] 반드시 알아야 할 5가지ORM 쿼리(https://chrisjune-13837.medium.com/django-%EB%8B%B9%EC%8B%A0%EC%9D%B4-%EB%AA%B0%EB%9E%90%EB%8D%98-orm-%EA%B8%B0%EC%B4%88%EC%99%80-%EC%8B%AC%ED%99%94-592a6017b5f5)
Django / select_related와 prefetch_related를 정복해보자 (https://bmh8993.github.io/Django/select_related%EC%99%80-prefetch_related%EB%A5%BC-%EC%A0%95%EB%B3%B5%ED%95%B4%EB%B3%B4%EC%9E%90/)
https://blog.myungseokang.dev/posts/database-access-optimization/
http://raccoonyy.github.io/django-annotate-and-aggregate-like-as-excel/
Django / select_related와 prefetch_related를 정복해보자 (https://bmh8993.github.io/Django/select_related%EC%99%80-prefetch_related%EB%A5%BC-%EC%A0%95%EB%B3%B5%ED%95%B4%EB%B3%B4%EC%9E%90/)
How to Filter for Empty or Null Values in a Django QuerySet(https://chartio.com/resources/tutorials/how-to-filter-for-empty-or-null-values-in-a-django-queryset/)