(self, **kwargs)
创建永久素材
创建永久素材
创建永久素材
def create_material(self, **kwargs):
        """创建永久素材"""
        app = kwargs.pop("app", self.instance)
        type = kwargs.pop("type", None)

        if type is None:
            raise NotImplementedError()
        if type == Material.Type.NEWS:
            return self.create_news(app=app, **kwargs)
        else:
            media_id = kwargs["media_id"]
            if type == Material.Type.VIDEO and "url" not in kwargs:
                data = app.client.material.get(media_id)
                kwargs["url"] = data.get("down_url")

            kwargs = {
                key: kwargs[key]
                for key in model_fields(self.model)
                if key in kwargs
            }
            query = dict(app=app, type=type, media_id=media_id)
            record = dict(app=app, type=type, **kwargs)
            return self.update_or_create(defaults=record, **query)[0]
def create_material ( self , * * kwargs ) : app = kwargs . pop ( "app" , self . instance ) type = kwargs . pop ( "type" , None ) if type is None : raise NotImplementedError ( ) if type == Material . Type . NEWS : return self . create_news ( app = app , * * kwargs ) else : media_id = kwargs [ "media_id" ] if type == Material . Type . VIDEO and "url" not in kwargs : data = app . client . material . get ( media_id ) kwargs [ "url" ] = data . get ( "down_url" ) kwargs = { key : kwargs [ key ] for key in model_fields ( self . model ) if key in kwargs } query = dict ( app = app , type = type , media_id = media_id ) record = dict ( app = app , type = type , * * kwargs ) return self . update_or_create ( defaults = record , * * query ) [ 0 ]