@classmethod
    def generate_index(cls, collection):
        # creating index if needed
        for index in deepcopy(cls.indexes):
            unique = False
            if 'unique' in index:
                unique = index.pop('unique')
            ttl = 300
            if 'ttl' in index:
                ttl = index.pop('ttl')

            given_fields = index.pop("fields", list())

            if isinstance(given_fields, tuple):
                fields = [given_fields]
            elif isinstance(given_fields, basestring):
                fields = [(given_fields, 1)]
            else:
                fields = []
                for field in given_fields:
                    if isinstance(field, basestring):
                        field = (field, 1)
                    fields.append(field)
            log.debug('Creating index for {}'.format(str(given_fields)))
            collection.ensure_index(fields, unique=unique, ttl=ttl, **index)
generate indexes from ``indexes`` class-attribute
dataset/ETHPy150Open namlook/mongokit/mongokit/document.py/Document.generate_index