> Jonathan, > > Many thanks for this. > > Sorry to be a pain , but I have a couple of follow on questions, so I'm > clear. > > 1. How should I best implement this code. As a custom tag or in the > view? > > 2. Any suggestions on how I should pass the product.id to the code? > > Thanks > > MerMer
1. The queryset we just defined will return a list of Product objects which have a 'rating' attribute in addition to their regular attributes. You would use this when retrieving Products in your view or defining a queryset for use by generic views in your urls.py. You can then access the rating with {{ product.rating }} in your templates. 2. You don't need to specify a product id - the extra select query we've provided results in something like the following in the SQL generated by Django's ORM: (SELECT AVG(appname_review.rating) FROM appname_review WHERE appname_review.product_id = appname_product.id) AS "rating" As such, you don't have to worry about doing anything else to specify which Product objects you want to get the average rating for - just use your Product.objects queryset methods as normal and use .extra(...) when you need the average rating pulled out as well - the ORM will already be restricting the resultset to the product rows representing the Product objects you're interested in and the .extra(...) query above will take advantage of that. Just shout if that's not clear enough :) Jonathan. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---