Commits

Anonymous committed 955ccd4

model indexes get inherited from parents, now

Comments (0)

Files changed (3)

-from .db_settings import get_indexes
+from .db_settings import get_model_indexes
 
 import datetime
 import sys
     def insert(self, data, return_id=False):
         gae_data = {}
         opts = self.query.get_meta()
-        indexes = get_indexes().get(self.query.model, {})
-        unindexed_fields = indexes.get('unindexed', ())
+        unindexed_fields = get_model_indexes(self.query.model)['unindexed']
         unindexed_cols = [opts.get_field(name).column
                           for name in unindexed_fields]
         kwds = {'unindexed_properties': unindexed_cols}
-from .db_settings import get_indexes
+from .db_settings import get_model_indexes
 from djangotoolbox.db.creation import NonrelDatabaseCreation
 
 class StringType(object):
         self.internal_type = internal_type
 
     def __mod__(self, field):
-        indexes = get_indexes().get(field['model'], {})
-        if field['name'] in indexes.get('indexed', ()):
+        indexes = get_model_indexes(field['model'])
+        if field['name'] in indexes['indexed']:
             return 'text'
-        elif field['name'] in indexes.get('unindexed', ()):
+        elif field['name'] in indexes['unindexed']:
             return 'longtext'
         return self.internal_type
 

db/db_settings.py

 
 # TODO: add support for eventual consistency setting on specific models
 
+def get_model_indexes(model):
+    indexes = get_indexes()
+    model_index = {'indexed': [], 'unindexed': []}
+    for item in reversed(model.mro()):
+        config = indexes.get(item, {})
+        model_index['indexed'].extend(config.get('indexed', ()))
+        model_index['unindexed'].extend(config.get('unindexed', ()))
+    return model_index
+
 def get_indexes():
     global FIELD_INDEXES
     if FIELD_INDEXES is None:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.