Django Haystack update index faster Django Haystack update index faster django django

Django Haystack update index faster


get_updated_field should return a string that contains the name of the attribute on the model that contains the date that the model was updated (haystack docs). A DateField with auto_now=True would be ideal for that (Django docs).

For example, my UserProfile model has a field named updated

models.py

class UserProfile(models.Model):    user = models.ForeignKey(User)    # lots of other fields snipped    updated = models.DateTimeField(auto_now=True)

search_indexes.py

class UserProfileIndex(SearchIndex):    text = CharField(document=True, use_template=True)    user = CharField(model_attr='user')    user_fullname = CharField(model_attr='user__get_full_name')    def get_model(self):        return UserProfile    def get_updated_field(self):        return "updated"

Then when I run ./manage.py update_index --age=10 it only indexes the user profiles updated in the last 10 hours.