Exemple #1
0
 def initialize(cls):
     """ Initialize the necessary stuffs of a model class
     Including:
         * Gathering fields and indices
         * Touch db if not exist.
     Called in ModelMeta's __new__
     """
     cls.db_name = cls.__name__.lower()
     cls.fields = []
     for fieldname, v in vars(cls).items():
         if isinstance(v, Field):
             v.fieldname = fieldname
             cls.fields.append(v)
             v.probe_index(cls)
     server = Server()
     if not server[cls.db_name]:
         server.create_db(cls.db_name)
Exemple #2
0
 def __init__(self, model, field):
     self.db_name = "idx--%s--%s" % (model.db_name, field.fieldname)
     server = Server()
     if not server[self.db_name]:
         server.create_db(self.db_name)