@@ -26,7 +26,7 @@ For the impatient::
2626    from myapp.models import Note 
2727     
2828     
29-     class NoteIndex(indexes.SearchIndex): 
29+     class NoteIndex(indexes.SearchIndex, indexes.Indexable ): 
3030        text = indexes.CharField(document=True, use_template=True) 
3131        author = indexes.CharField(model_attr='user') 
3232        pub_date = indexes.DateTimeField(model_attr='pub_date') 
@@ -124,13 +124,13 @@ contents of that field, which avoids the database hit.:
124124
125125Within ``myapp/search_indexes.py ``::
126126
127-     class NoteIndex(SearchIndex): 
127+     class NoteIndex(SearchIndex, indexes.Indexable ): 
128128        text = CharField(document=True, use_template=True) 
129129        author = CharField(model_attr='user') 
130130        pub_date = DateTimeField(model_attr='pub_date') 
131131        # Define the additional field. 
132132        rendered = CharField(use_template=True, indexed=False) 
133-      
133+ 
134134Then, inside a template named ``search/indexes/myapp/note_rendered.txt ``::
135135
136136    <h2>{{ object.title }}</h2> 
@@ -224,11 +224,14 @@ To keep with our existing example, one use case might be altering the name
224224inside the ``author `` field to be "firstname lastname <email>". In this case,
225225you might write the following code::
226226
227-     class NoteIndex(SearchIndex): 
227+     class NoteIndex(SearchIndex, indexes.Indexable ): 
228228        text = CharField(document=True, use_template=True) 
229229        author = CharField(model_attr='user') 
230230        pub_date = DateTimeField(model_attr='pub_date') 
231231         
232+         def get_model(self): 
233+             return Note 
234+          
232235        def prepare_author(self, obj): 
233236            return "%s <%s>" % (obj.user.get_full_name(), obj.user.email) 
234237
@@ -239,11 +242,14 @@ data may come from the field itself.
239242Just like ``Form.clean_FOO ``, the field's ``prepare `` runs before the
240243``prepare_FOO ``, allowing you to access ``self.prepared_data ``. For example::
241244
242-     class NoteIndex(SearchIndex): 
245+     class NoteIndex(SearchIndex, indexes.Indexable ): 
243246        text = CharField(document=True, use_template=True) 
244247        author = CharField(model_attr='user') 
245248        pub_date = DateTimeField(model_attr='pub_date') 
246249         
250+         def get_model(self): 
251+             return Note 
252+          
247253        def prepare_author(self, obj): 
248254            # Say we want last name first, the hard way. 
249255            author = u'' 
@@ -257,12 +263,15 @@ Just like ``Form.clean_FOO``, the field's ``prepare`` runs before the
257263This method is fully function with ``model_attr ``, so if there's no convenient
258264way to access the data you want, this is an excellent way to prepare it::
259265
260-     class NoteIndex(SearchIndex): 
266+     class NoteIndex(SearchIndex, indexes.Indexable ): 
261267        text = CharField(document=True, use_template=True) 
262268        author = CharField(model_attr='user') 
263269        categories = MultiValueField() 
264270        pub_date = DateTimeField(model_attr='pub_date') 
265271         
272+         def get_model(self): 
273+             return Note 
274+          
266275        def prepare_categories(self, obj): 
267276            # Since we're using a M2M relationship with a complex lookup, 
268277            # we can prepare the list here. 
@@ -280,11 +289,14 @@ Overriding this method is useful if you need to collect more than one piece
280289of data or need to incorporate additional data that is not well represented
281290by a single ``SearchField ``. An example might look like::
282291
283-     class NoteIndex(SearchIndex): 
292+     class NoteIndex(SearchIndex, indexes.Indexable ): 
284293        text = CharField(document=True, use_template=True) 
285294        author = CharField(model_attr='user') 
286295        pub_date = DateTimeField(model_attr='pub_date') 
287296         
297+         def get_model(self): 
298+             return Note 
299+          
288300        def prepare(self, object): 
289301            self.prepared_data = super(NoteIndex, self).prepare(object) 
290302             
@@ -511,11 +523,14 @@ By default, returns ``all()`` on the model's default manager.
511523
512524Example::
513525
514-     class NoteIndex(SearchIndex): 
526+     class NoteIndex(SearchIndex, indexes.Indexable ): 
515527        text = CharField(document=True, use_template=True) 
516528        author = CharField(model_attr='user') 
517529        pub_date = DateTimeField(model_attr='pub_date') 
518530         
531+         def get_model(self): 
532+             return Note 
533+          
519534        def load_all_queryset(self): 
520535            # Pull all objects related to the Note in search results. 
521536            return Note.objects.all().select_related() 
@@ -585,18 +600,20 @@ For the impatient::
585600    from myapp.models import Note 
586601     
587602    # All Fields 
588-     class AllNoteIndex(indexes.ModelSearchIndex): 
603+     class AllNoteIndex(indexes.ModelSearchIndex, indexes.Indexable ): 
589604        class Meta: 
590-             pass  
605+             model = Note  
591606     
592607    # Blacklisted Fields 
593-     class LimitedNoteIndex(indexes.ModelSearchIndex): 
608+     class LimitedNoteIndex(indexes.ModelSearchIndex, indexes.Indexable ): 
594609        class Meta: 
610+             model = Note 
595611            excludes = ['user'] 
596612     
597613    # Whitelisted Fields 
598-     class NoteIndex(indexes.ModelSearchIndex): 
614+     class NoteIndex(indexes.ModelSearchIndex, indexes.Indexable ): 
599615        class Meta: 
616+             model = Note 
600617            fields = ['user', 'pub_date'] 
601618         
602619        # Note that regular ``SearchIndex`` methods apply. 
0 commit comments