Instead of spoon-feeding you, I would recommend using DDT and check out the query that is generated and whether if it satisfies your use-case. By this, you will know how exactly select_related works and also the number of queries that gets fired in the page and what happens once you use this.
On Thu, May 1, 2014 at 6:52 PM, Andreas Bloch <ablochs@gmail.com> wrote:
Okay, I'm a little confused here about using select_ralated...--Can you only run select_related on a table that HAS a foreign key not a table that IS a foreign key?What if I want to go:SELECT * FROM product LEFT JOIN review on product.id = review.product_id LEFT JOIN comments ON product.id = comment.product_id
example models.pyclass Product(models.Model):name =class Review(models.Model):product = models.Foreignkey(Product)rating =class Comments(models.Model):product = models.Foreignkey(Product)text =In my templates I want to be able to loop through all reviews and comments for each product without hitting the database multiple times...How can you achieve this?
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5370daf6-58d0-4573-a282-36c4a70a5937%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAN7tdFSqW4cmAdrKsCNqP%3D9BwRrxfF8XNx51_2yKFuqNw7KtsA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment