Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8105337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:08:02+00:00 2026-06-06T00:08:02+00:00

Currently I have a database of Courses, and it has 6 columns: class Course(models.Model):

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:08:03+00:00Added an answer on June 6, 2026 at 12:08 am

    Haystack doesn’t require any changes to your models. The recommended method is to use a template:

    class CourseIndex(indexes.SearchIndex, indexes.Indexable):
        text = indexes.CharField(document=True, use_template=True)
        ...
    

    Then, you create a file named in the form of templates/search/indexes/[app]/[model]_[indexfield].txt. So, in this case it would be templates/search/indexes/yourapp/course_text.txt. Then, you use standard Django template tags and such to create a plain text representation of your model:

    {{ object.title }}
    {{ object.number }}
    {{ object.department.name }}
    

    Add as much info as you like. If you have any rich text fields that include HTML, remember to use striptags, so you don’t end up with garbage in your index.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I have a database with the following relationships: One Client has multiple Entities
I have a database that logs when an employee has attended a course and
I have a data model in Doctrine/symfony. I have a 'Course' which has many
Currently I have database with the following associations: One Client to Many Intakes One
I currently have a MySQL database which I was hoping to use to store
I currently have a Postgres 8.4 database that contains a varchar(10000) column. I'd like
I currently have a bunch of SQLCHAR objects from a database query. The query
I currently have a problem attepting to update a record within my database. I
I currently have this code which reads the first field in a database record
I'm trying to normalize a mysql database.... I currently have a table that contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.