@@ -12,28 +12,31 @@ class AlgoliaIndexError(Exception):
12
12
class AlgoliaIndex (object ):
13
13
'''An index in the Algolia backend.'''
14
14
15
- # Use to specify a custom field that will be used for the objectID.
15
+ # Used to specify a custom field that will be used for the objectID.
16
16
# This field should be unique.
17
17
custom_objectID = None
18
18
19
- # Use to specify the fields that should be included in the index.
19
+ # Used to specify the fields that should be included in the index.
20
20
fields = ()
21
21
22
- # Use to specify the geo-fields that should be used for location search.
22
+ # Used to specify the geo-fields that should be used for location search.
23
23
# The attribute should be a callable that returns a tuple.
24
24
geo_field = None
25
25
26
- # Use to specify the field that should be used for filtering by tag.
26
+ # Used to specify the field that should be used for filtering by tag.
27
27
tags = None
28
28
29
- # Use to specify the index to target on Algolia.
29
+ # Used to specify the index to target on Algolia.
30
30
index_name = None
31
31
32
- # Use to specify the settings of the index.
32
+ # Used to specify the settings of the index.
33
33
settings = {}
34
34
35
- # Use to specify a callable that say if the instance should be indexed.
36
- # The attribute should be a callable that returns a boolean.
35
+ # Used to specify if the instance should be indexed.
36
+ # The attribute should be either:
37
+ # - a callable that returns a boolean.
38
+ # - a BooleanField
39
+ # - a boolean property or attribute
37
40
should_index = None
38
41
39
42
# Instance of the index from algoliasearch client
@@ -52,7 +55,7 @@ def __init__(self, model, client):
52
55
53
56
# Avoid error when there is only one field to index
54
57
if isinstance (self .fields , str ):
55
- self .fields = (self .fields , )
58
+ self .fields = (self .fields ,)
56
59
57
60
# Check fields
58
61
for field in self .fields :
@@ -63,7 +66,7 @@ def __init__(self, model, client):
63
66
# Check custom_objectID
64
67
if self .custom_objectID :
65
68
if not (hasattr (model , self .custom_objectID ) or
66
- (self .custom_objectID in all_fields )):
69
+ (self .custom_objectID in all_fields )):
67
70
raise AlgoliaIndexError ('{} is not an attribute of {}.' .format (
68
71
self .custom_objectID , model ))
69
72
0 commit comments