Currently I have a database of Courses, and it has 6 columns:
class Course(models.Model):
title = models.CharField(max_length=50)
number = models.CharField(max_length=12)
Cat1 = models.BooleanField()
Cat2 = models.BooleanField()
Cat3 = models.BooleanField()
department = models.ForeignKey(Department)
The unicode method for this course is made to output something like:
def __unicode__(self):
return u'%s %s %s %s %s %s' % (self.department, self.number, self.title, 'CAT1' if self.Cat1 else '','Cat2' if self.Cat2 else '','Cat3' if self.Cat3 else '')
Which returns something like: ENG 1104 Academic Writing Cat1 Cat3
I'm trying to implement a search to find courses by text queries, so I tried Haystack (with Whoosh as the engine), but to make it easier to index I just added a new column to the model named text, in which I just added the Unicode text of each course. This method works pretty well, but obviously its not robust and because this is only a small project of me for learning purposes, I would like to know more efficient ways of accomplishing this search. Any Ideas?
u'%(department)s' % {'department': self.department}. You can spread the dictionary over multiple lines, making it much more readable, and you can see at a glance what info is going where.