from tornado.options import define,options

class BaseModel():
    def __init__():
        self.db_client = options.db_client;
        if not hasattr(self, "db"):
            self.db = "db_paas"
        if not hasattr(self,"table"):
            self.table = "t_user"
        if not hasattr(self,"key"):
            self.key = "_id"
            
        self.db_conn  = self.db_client.connection(collectionname=self.table, dbname=self.db_client)
        
        
    def get_list(callback):
        self.db_conn.find(callback=callback)
        
         
    
    
@@ -35,16 +35,125 @@
 ,options
+%0Aimport tornado.gen%0Aimport pymongo%0A%0A__all__=%5B%22get_list%22,%22get_one%22,%22update%22,%22insert%22,%22delete%22,%22exsit%22,%22count%22%5D
 %0A%0Aclass 
@@ -229,16 +229,104 @@
 client;%0A
+        self.module = self.__module__%0A        self.class_name = self.__class__.__name__%0A
         
@@ -379,17 +379,33 @@
 b = 
-%22db_paas%22
+self.module.split('.')%5B1%5D
 %0A   
@@ -468,16 +468,23 @@
 e = 
-%22t_user%22
+self.class_name
 %0A   
@@ -539,16 +539,32 @@
 f.key = 
+self.class_name+
 %22_id%22%0A  
@@ -565,28 +565,25 @@
 id%22%0A        
-    
+%0A
 %0A        sel
@@ -710,72 +710,1012 @@
 ist(
-callback):%0A        self.db_conn.find(callback=callback)%0A        
+spec=None,fileds=None,sorts=None,skip=0,limit=20,callback):%0A        if(spec==None or isinstance(spec,dict)):%0A            spec = %7B%7D%0A        if(fields==None or isinstance(fields,dict)):%0A            if not hasattr(self,%22fields%22):%0A                fields = self.fields%0A            else:%0A                fields = %7B%22_id%22:True%7D%0A        if(sorts==None or isinstance(sorts,list):%0A            sorts = %5B%5D%0A            sorts.append(%5B%22_id%22, pymongo.DESCENDING%5D)%0A        result_list,error = yield tornado.gen.Task( self.db_conn.find,%0A            spec = spec,fields = fields,%0A            sort = sorts,limit = limit,skip = skip%0A        )%0A        callback(result_list)%0A    %0A    def get_one(spec_or_id,fields,callback):%0A        if(fields==None or isinstance(fields,dict)):%0A            if not hasattr(self,%22fields%22):%0A                fields = self.fields%0A            else:%0A                fields = %7B%22_id%22:True%7D%0A        result,error = yield tornado.gen.Task( self.db_conn.find_one,spec,fields = fields)%0A        callback(result)
 %0A   
@@ -1722,16 +1722,17 @@
       %0A    %0A    
+%0A

Update __init__.py