From: Charles Holbrow Date: Wed, 27 Feb 2013 23:58:38 +0000 (-0500) Subject: Adding redundant school_name field to courses to enable faster server side filtering... X-Git-Tag: release-20150131~505^2~2 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=7740834baeccd835a1b17a0fe3b3d6a3a5a7b007;p=oweals%2Fkarmaworld.git Adding redundant school_name field to courses to enable faster server side filtering. requires: for c in Course.objects.all(): c.save() --- diff --git a/karmaworld/apps/courses/models.py b/karmaworld/apps/courses/models.py index 40deedc..882db84 100644 --- a/karmaworld/apps/courses/models.py +++ b/karmaworld/apps/courses/models.py @@ -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)) diff --git a/karmaworld/apps/courses/views.py b/karmaworld/apps/courses/views.py index c704bfb..08159d8 100644 --- a/karmaworld/apps/courses/views.py +++ b/karmaworld/apps/courses/views.py @@ -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 ]