# HG changeset patch # User Brian Neal # Date 1451449302 21600 # Node ID 7e0c3cbd3cda4272e248b8ac2377963b51ae5367 # Parent b7b98c729abcf86fda42371b52a2805e414389e6 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. diff -r b7b98c729abc -r 7e0c3cbd3cda forums/views/attachments.py --- 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') diff -r b7b98c729abc -r 7e0c3cbd3cda sg101/templates/forums/display_post.html --- a/sg101/templates/forums/display_post.html Sun Dec 27 12:00:51 2015 -0600 +++ b/sg101/templates/forums/display_post.html Tue Dec 29 22:21:42 2015 -0600 @@ -43,13 +43,15 @@

Last edited: {{ post.update_date|date:"M d, Y H:i:s" }}

{% endif %} - {% if post.attachments.all %} -
- {% for item in post.attachments.all %} -
{{ item.html|safe }}
- {% endfor %} -
- {% endif %} + {% with attachments=post.attachments.all %} + {% if attachments %} +
+ {% for item in attachments %} +
{{ item.html|safe }}
+ {% endfor %} +
+ {% endif %} + {% endwith %}
Top {% if can_reply %}