from haystack import indexes
from books.models import Book, Series


class BookIndex(indexes.SearchIndex, indexes.Indexable):

    text = indexes.CharField(document=True, use_template=True)
    library = indexes.IntegerField(model_attr="library_id")

    def get_model(self):
        return Book

    def index_queryset(self, using=None):
        return self.get_model().objects.all()


class SeriesIndex(indexes.SearchIndex, indexes.Indexable):

    text = indexes.CharField(document=True, use_template=True)
    library = indexes.IntegerField(model_attr="library_id")

    def get_model(self):
        return Series

    def index_queryset(self, using=None):
        return self.get_model().objects.all()
from haystack import indexes
from books.models import Book, Series


class BookIndex(indexes.SearchIndex, indexes.Indexable):

    text = indexes.CharField(document=True, use_template=True)
    library = indexes.IntegerField(model_attr="library_id")

    def get_model(self):
        return Book

    def index_queryset(self, using=None):
        return self.get_model().objects.all()

    def get_updated_field(self):
        return 'modified'


class SeriesIndex(indexes.SearchIndex, indexes.Indexable):

    text = indexes.CharField(document=True, use_template=True)
    library = indexes.IntegerField(model_attr="library_id")

    def get_model(self):
        return Series

    def index_queryset(self, using=None):
        return self.get_model().objects.all()

    def get_updated_field(self):
        return 'modified'
Add fields to index so 'update_index' works
Add fields to index so 'update_index' works

  from haystack import indexes
  from books.models import Book, Series
  
  
  class BookIndex(indexes.SearchIndex, indexes.Indexable):
  
      text = indexes.CharField(document=True, use_template=True)
      library = indexes.IntegerField(model_attr="library_id")
  
      def get_model(self):
          return Book
  
      def index_queryset(self, using=None):
          return self.get_model().objects.all()
  
+     def get_updated_field(self):
+         return 'modified'
+ 
  
  class SeriesIndex(indexes.SearchIndex, indexes.Indexable):
  
      text = indexes.CharField(document=True, use_template=True)
      library = indexes.IntegerField(model_attr="library_id")
  
      def get_model(self):
          return Series
  
      def index_queryset(self, using=None):
          return self.get_model().objects.all()
+ 
+     def get_updated_field(self):
+         return 'modified'
Add fields to index so 'update_index' works
## Code Before:
from haystack import indexes
from books.models import Book, Series


class BookIndex(indexes.SearchIndex, indexes.Indexable):

    text = indexes.CharField(document=True, use_template=True)
    library = indexes.IntegerField(model_attr="library_id")

    def get_model(self):
        return Book

    def index_queryset(self, using=None):
        return self.get_model().objects.all()


class SeriesIndex(indexes.SearchIndex, indexes.Indexable):

    text = indexes.CharField(document=True, use_template=True)
    library = indexes.IntegerField(model_attr="library_id")

    def get_model(self):
        return Series

    def index_queryset(self, using=None):
        return self.get_model().objects.all()
## Instruction:
Add fields to index so 'update_index' works
## Code After:
from haystack import indexes
from books.models import Book, Series


class BookIndex(indexes.SearchIndex, indexes.Indexable):

    text = indexes.CharField(document=True, use_template=True)
    library = indexes.IntegerField(model_attr="library_id")

    def get_model(self):
        return Book

    def index_queryset(self, using=None):
        return self.get_model().objects.all()

    def get_updated_field(self):
        return 'modified'


class SeriesIndex(indexes.SearchIndex, indexes.Indexable):

    text = indexes.CharField(document=True, use_template=True)
    library = indexes.IntegerField(model_attr="library_id")

    def get_model(self):
        return Series

    def index_queryset(self, using=None):
        return self.get_model().objects.all()

    def get_updated_field(self):
        return 'modified'