Hi. select_related is used for folloing foreign keys. So if u have, say, product and its producer field in it u can do smth like: Product.objects.select_related('producer') and in ur templates accessing product.producer won't hit the database.
Notice that here we have a relationship where only one producer can be ralated to product. But you obviously can't do it when you have multiple objects attached to one.
Producer.objects.prefetch_related('review_set', 'comments_set') will populate product.review_set.all() and product.comments_set.all() for you.
четверг, 1 мая 2014 г., 17:22:52 UTC+4 пользователь Andreas Bloch написал: