[Answered ]-Django haystack inheritance problems



You can add a is_employee field to your SearchIndex class for Person model.

class Person(models.Model):
    # your existing code goes here

    def is_employee(self):
              self.employee # try to get the associated Employee object
              return True
         except Employee.DoesNotExist:
              return False

class PersonSearchIndex(SearchIndex):
    # your existing code goes here
    is_employee = BooleanField(model_attr='is_employee')

After that you can use this field to exclude the persons that are also Employees.

query = SearchQuerySet().filter(is_employee=False)

You can also replace this field with a more generic field person_type if you have more than one person types.

Leave a comment