remove query per row on search page

This commit is contained in:
Glen Chiacchieri 2013-04-04 19:01:57 +00:00
parent cbd9c1158d
commit dd60f43182
2 changed files with 11 additions and 8 deletions

View file

@ -29,11 +29,11 @@
<select id="forum" name="forum">
<option value="0">{% trans "All forums" %}</option>
{% for category in categories %}
<optgroup label="{{ category }}">
{% for forum in category.forums.all %}
<option value="{{ forum.id }}">{{ forum }}</option>
{% endfor %}
</optgroup>
<optgroup label="{{ category }}">
{% for forum in category.forums.all %}
<option value="{{ forum.id }}">{{ forum }}</option>
{% endfor %}
</optgroup>
{% endfor %}
</select>
</label>

View file

@ -143,9 +143,12 @@ def search(request, full=True):
template_dir = 'djangobb_forum/' if full else 'djangobb_forum/mobile/'
def _render_search_form(form=None):
return render(request, template_dir + 'search_form.html', {'categories': Category.objects.all(),
'form': form,
})
# TODO: remove 'in' clause from following query
categories_with_forums = Category.objects.prefetch_related('forums')
return render(request, template_dir + 'search_form.html', {
'categories': categories_with_forums,
'form': form,
})
if not 'action' in request.GET:
return _render_search_form(form=PostSearchForm())