Adding redundant school_name field to courses to enable faster server side filtering...
authorCharles Holbrow <charlesholbrow@gmail.com>
Wed, 27 Feb 2013 23:58:38 +0000 (18:58 -0500)
committerCharles Holbrow <charlesholbrow@gmail.com>
Wed, 27 Feb 2013 23:58:38 +0000 (18:58 -0500)
karmaworld/apps/courses/models.py
karmaworld/apps/courses/views.py

index 40deedc0c894d4f160338e42596a397c446143ed..882db84998832251ff857178c4b225511ef7b876 100644 (file)
@@ -75,8 +75,10 @@ class Course(models.Model):
     instructor_name     = models.CharField(max_length=255, blank=True, null=True)
     instructor_email    = models.EmailField(blank=True, null=True)
 
-    updated_at      = models.DateTimeField(default=datetime.datetime.utcnow)
+    # Save school name redundantly to speed filtering
+    school_name     = models.CharField(max_length=255, blank=True, null=True)
 
+    updated_at      = models.DateTimeField(default=datetime.datetime.utcnow)
     created_at      = models.DateTimeField(auto_now_add=True)
 
 
@@ -92,6 +94,8 @@ class Course(models.Model):
 
     def save(self, *args, **kwargs):
         """ Save school and generate a slug if one doesn't exist """
+        if self.school_name != self.school.name:
+            self.school_name = self.school.name
         super(Course, self).save(*args, **kwargs) # generate a self.id
         if not self.slug:
             self.slug = defaultfilters.slugify("%s %s" % (self.name, self.id))
index c704bfba9089b9243961ee54f0145ada7f5f82f0..08159d80812360bbcd8c65abdd73700c0c27423b 100644 (file)
@@ -78,7 +78,8 @@ class CourseAjaxList(BaseListView):
         queries = [
             (
                 Q(name__icontains=s) |
-                Q(instructor_name__icontains=s)
+                Q(instructor_name__icontains=s) |
+                Q(school_name__icontains=s)
             ) 
             for s in search_strings 
         ]