
from haystack import indexes

from .models import Book


# Classes #####################################################################

class BookIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    title = indexes.CharField(model_attr='title')
    subtitle = indexes.CharField(model_attr='subtitle')
    isbn = indexes.CharField(model_attr='isbn')
    author = indexes.CharField(model_attr='author')
    illustrator = indexes.CharField(model_attr='illustrator')
    editor = indexes.CharField(model_attr='editor')
    collection = indexes.CharField(model_attr='collection')
    keywords = indexes.CharField(model_attr='keywords')
    synopsis = indexes.CharField(model_attr='synopsis')

    def get_model(self):
        return Book


from haystack import indexes

from .models import Book


# Classes #####################################################################

class BookIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    title = indexes.CharField(model_attr='title')
    subtitle = indexes.CharField(model_attr='subtitle', blank=True)
    isbn = indexes.CharField(model_attr='isbn')
    author = indexes.CharField(model_attr='author')
    illustrator = indexes.CharField(model_attr='illustrator', blank=True)
    editor = indexes.CharField(model_attr='editor')
    collection = indexes.CharField(model_attr='collection', blank=True)
    keywords = indexes.CharField(model_attr='keywords', blank=True)
    synopsis = indexes.CharField(model_attr='synopsis')

    def get_model(self):
        return Book

Allow some blank fields in Booki model from search
Allow some blank fields in Booki model from search

  
  from haystack import indexes
  
  from .models import Book
  
  
  # Classes #####################################################################
  
  class BookIndex(indexes.SearchIndex, indexes.Indexable):
      text = indexes.CharField(document=True, use_template=True)
      title = indexes.CharField(model_attr='title')
-     subtitle = indexes.CharField(model_attr='subtitle')
+     subtitle = indexes.CharField(model_attr='subtitle', blank=True)
      isbn = indexes.CharField(model_attr='isbn')
      author = indexes.CharField(model_attr='author')
-     illustrator = indexes.CharField(model_attr='illustrator')
+     illustrator = indexes.CharField(model_attr='illustrator', blank=True)
      editor = indexes.CharField(model_attr='editor')
-     collection = indexes.CharField(model_attr='collection')
+     collection = indexes.CharField(model_attr='collection', blank=True)
-     keywords = indexes.CharField(model_attr='keywords')
+     keywords = indexes.CharField(model_attr='keywords', blank=True)
      synopsis = indexes.CharField(model_attr='synopsis')
  
      def get_model(self):
          return Book
  
Allow some blank fields in Booki model from search
## Code Before:

from haystack import indexes

from .models import Book


# Classes #####################################################################

class BookIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    title = indexes.CharField(model_attr='title')
    subtitle = indexes.CharField(model_attr='subtitle')
    isbn = indexes.CharField(model_attr='isbn')
    author = indexes.CharField(model_attr='author')
    illustrator = indexes.CharField(model_attr='illustrator')
    editor = indexes.CharField(model_attr='editor')
    collection = indexes.CharField(model_attr='collection')
    keywords = indexes.CharField(model_attr='keywords')
    synopsis = indexes.CharField(model_attr='synopsis')

    def get_model(self):
        return Book

## Instruction:
Allow some blank fields in Booki model from search
## Code After:

from haystack import indexes

from .models import Book


# Classes #####################################################################

class BookIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    title = indexes.CharField(model_attr='title')
    subtitle = indexes.CharField(model_attr='subtitle', blank=True)
    isbn = indexes.CharField(model_attr='isbn')
    author = indexes.CharField(model_attr='author')
    illustrator = indexes.CharField(model_attr='illustrator', blank=True)
    editor = indexes.CharField(model_attr='editor')
    collection = indexes.CharField(model_attr='collection', blank=True)
    keywords = indexes.CharField(model_attr='keywords', blank=True)
    synopsis = indexes.CharField(model_attr='synopsis')

    def get_model(self):
        return Book
