def test_blocks_not_in_indexed_objects(self): obj = models.Novel(title="Don't index me!", publication_date=date(2017, 10, 18), number_of_pages=100) obj.save() # We've told it not to index anything with the title "Don't index me" # get_indexed_instance should return None indexed_instance = index.get_indexed_instance(obj.book_ptr) self.assertEqual(indexed_instance, None)
def test_gets_specific_class(self): obj = models.SearchTestChild( title="Hello", live=True, ) obj.save() # Running the command with the parent class should find the specific class again indexed_instance = index.get_indexed_instance(obj.searchtest_ptr) self.assertEqual(indexed_instance, obj)
def test_gets_instance(self): obj = models.SearchTest( title="Hello", live=True, ) obj.save() # Should just return the object indexed_instance = index.get_indexed_instance(obj) self.assertEqual(indexed_instance, obj)
def test_blocks_not_in_indexed_objects(self): obj = models.SearchTestChild( title="Don't index me!", live=True, ) obj.save() # We've told it not to index anything with the title "Don't index me" # get_indexed_instance should return None indexed_instance = index.get_indexed_instance(obj.searchtest_ptr) self.assertEqual(indexed_instance, None)
def post_save_signal_handler(instance, **kwargs): update_fields = kwargs.get('update_fields') social_fields = frozenset(('cached_facebook_count', 'cached_last_updated')) if update_fields == social_fields: return # Don't update the search index if we are just updating facebook page counts indexed_instance = get_indexed_instance(instance) if indexed_instance: for backend in get_search_backends(with_auto_update=True): backend.add(indexed_instance)
def test_gets_specific_class(self): obj = models.Novel.objects.get(id=1) # Running the command with the parent class should find the specific class again indexed_instance = index.get_indexed_instance(obj.book_ptr) self.assertEqual(indexed_instance, obj)
def test_gets_instance(self): obj = models.Author.objects.get(id=1) # Should just return the object indexed_instance = index.get_indexed_instance(obj) self.assertEqual(indexed_instance, obj)