diff forums/views/attachments.py @ 1037:7e0c3cbd3cda

Fix bad select_related call. In Django 1.8, select_related now throws an error if you give it an invalid field. This was happening. Fix that query. Also noticed an extra query generated in the display_post template. Fixed.
author Brian Neal <bgneal@gmail.com>
date Tue, 29 Dec 2015 22:21:42 -0600
parents 89b240fe9297
children
line wrap: on
line diff
--- a/forums/views/attachments.py	Sun Dec 27 12:00:51 2015 -0600
+++ b/forums/views/attachments.py	Tue Dec 29 22:21:42 2015 -0600
@@ -9,6 +9,7 @@
 from django.http import HttpResponseBadRequest
 from django.http import HttpResponseNotFound
 
+from forums.models import Attachment
 from forums.models import Post
 
 
@@ -30,8 +31,8 @@
     except Post.DoesNotExist:
         return HttpResponseNotFound("That post doesn't exist.")
 
-    embeds = post.attachments.all().select_related('embed')
-    data = [{'id': embed.id, 'html': embed.html} for embed in embeds]
+    attachments = Attachment.objects.filter(post=post).select_related('embed')
+    data = [{'id': a.embed.id, 'html': a.embed.html} for a in attachments]
 
     return HttpResponse(json.dumps(data), content_type='application/json')