#NEWLINE# def product_reviews( request , product_id = None ) : #NEWLINE# #INDENT# product_list = products . models . Product . objects . order_by ( 'name' ) #NEWLINE# review_qs = reviews . models . Review . objects . order_by ( '-created' ) #NEWLINE# review_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# users = { #NEWLINE# #INDENT# ( - 1 ) : 'Anonymous' , #NEWLINE# #UNINDENT# } #NEWLINE# for db_alias in router . alias_iter ( ) : #NEWLINE# #INDENT# current_qs = review_qs . using ( db_alias ) #NEWLINE# review_ids = [ obj . author_id for obj in current_qs ] #NEWLINE# users . update ( dict ( auth_models . User . objects . filter ( id__in = review_ids ) . values_list ( 'id' , 'username' ) ) ) #NEWLINE# for review in current_qs : #NEWLINE# #INDENT# review . reviewer = users [ review . author_id ] #NEWLINE# review_dict . setdefault ( review . product_id , [ ] ) . append ( review ) #NEWLINE# #UNINDENT# #UNINDENT# for product in product_list : #NEWLINE# #INDENT# product . reviews = review_dict . get ( product . id , [ ] ) #NEWLINE# #UNINDENT# data = { #NEWLINE# #INDENT# 'title' : 'All product reviews' , #NEWLINE# 'products' : product_list , #NEWLINE# #UNINDENT# } #NEWLINE# return render_to_response ( 'reviews/product_reviews.html' , data , RequestContext ( request ) )