Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Issue #45: Refactored database queries to use foreignKey__fieldName in #46

merged 1 commit into from

1 participant

Kyle Rogers
Kyle Rogers

order to reduce database queries.

Kyle Rogers rogerskw merged commit 03707b4 into from
Kyle Rogers rogerskw deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 8, 2014
  1. Kyle Rogers

    Issue #45: Refactored database queries to use foreignKey__fieldName in

    rogerskw authored
    order to reduce database queries.
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 5 deletions.
  1. +5 −5 articles/
10 articles/
@@ -2,9 +2,10 @@
from django.http import HttpResponse
from django.template import Context, loader
+from django.db.models import Q
import math
-from articles.models import Article, ArticleCategory, ArticleEntity, Gallery, Picture
+from articles.models import Article, ArticleEntity
from listing.pages import PageHelper
default_count_per_page = 5
@@ -13,11 +14,10 @@
def general_listing(request, eventType, category):
t = loader.get_template('article_list.html')
+ category_query = Q()
if category != None:
- type_id = ArticleCategory.objects.filter(name=category)[0].id
- article_list = Article.objects.filter(category=type_id).order_by('date').reverse()
- else:
- article_list = Article.objects.all().order_by('date').reverse()
+ category_query = Q(category__name=category)
+ article_list = Article.objects.filter(category_query).order_by('date').reverse()
article_count = PageHelper.get_request_count(request, default_count_per_page, max_count_per_page)
page_number = PageHelper.get_page_number(request)
articles_range_min = (page_number - 1) * article_count
Something went wrong with that request. Please try again.