(self, user_dict=None)
重新同步用户数据
重新同步用户数据
重新同步用户数据
def update(self, user_dict=None):
        """重新同步用户数据"""
        if user_dict and isinstance(user_dict, dict):
            # 小程序用户有些字段和公众号不同
            if "avatarUrl" in user_dict:
                user_dict["headimgurl"] = user_dict.pop("avatarUrl")
            if "gender" in user_dict:
                user_dict["sex"] = user_dict.pop("gender")

            field_names = model_fields(self)
            for key in user_dict:
                if key.lower() in field_names:
                    setattr(self, key.lower(), user_dict[key])
            self.save()
        else:
            self.fetch_user(self.app, self.openid)
        self.refresh_from_db()
def update ( self , user_dict = None ) : if user_dict and isinstance ( user_dict , dict ) : # 小程序用户有些字段和公众号不同 if "avatarUrl" in user_dict : user_dict [ "headimgurl" ] = user_dict . pop ( "avatarUrl" ) if "gender" in user_dict : user_dict [ "sex" ] = user_dict . pop ( "gender" ) field_names = model_fields ( self ) for key in user_dict : if key . lower ( ) in field_names : setattr ( self , key . lower ( ) , user_dict [ key ] ) self . save ( ) else : self . fetch_user ( self . app , self . openid ) self . refresh_from_db ( )