def create(self, data, fields=[], models={}):
        '''
        Create model attributes
        '''
        if not fields: fields = self.fields
        if not models and hasattr(self, 'models'): models = self.models
        for field in fields:
            setattr(self,field,None)
        if not data: return None
        for k, v in data.iteritems():
            if type(v) in (str, unicode):
                v = v.strip()
            if models and k in models:
                if type(v) == dict:
                    lists = []
                    for k2, v2 in v.iteritems():
                        if type(v2) == list:
                            for d in v2:
                                model = models[k]()
                                lists.append(model.create(d))
                    if not lists:
                        model = models[k]()
                        v = model.create(v)
                    else:
                        v = lists
                else:
                    model = models[k]()
                    v = model.create(v)
            setattr(self,k,v)
        return self
def create ( self , data , fields = [ ] , models = { } ) : if not fields : fields = self . fields if not models and hasattr ( self , 'models' ) : models = self . models for field in fields : setattr ( self , field , None ) if not data : return None for k , v in data . iteritems ( ) : if type ( v ) in ( str , unicode ) : v = v . strip ( ) if models and k in models : if type ( v ) == dict : lists = [ ] for k2 , v2 in v . iteritems ( ) : if type ( v2 ) == list : for d in v2 : model = models [ k ] ( ) lists . append ( model . create ( d ) ) if not lists : model = models [ k ] ( ) v = model . create ( v ) else : v = lists else : model = models [ k ] ( ) v = model . create ( v ) setattr ( self , k , v ) return self
Create model attributes