(self, **kwargs)
return news
创建永久图文素材
创建永久图文素材
创建永久图文素材
def create_news(self, **kwargs):
        """创建永久图文素材"""
        from . import Article

        app = kwargs.pop("app", self.instance)

        # 插入media
        query = dict(app=app, media_id=kwargs["media_id"])
        record = dict(
            type=Material.Type.NEWS,
            update_time=kwargs["update_time"]
        )
        record.update(query)
        news, created = self.update_or_create(defaults=record, **query)
        if not created:
            # 移除所有article重新插入
            news.articles.all().delete()

        articles = Article.from_mp(kwargs, news)
        news.articles.bulk_create(articles)
        return news
def create_news ( self , * * kwargs ) : from . import Article app = kwargs . pop ( "app" , self . instance ) # 插入media query = dict ( app = app , media_id = kwargs [ "media_id" ] ) record = dict ( type = Material . Type . NEWS , update_time = kwargs [ "update_time" ] ) record . update ( query ) news , created = self . update_or_create ( defaults = record , * * query ) if not created : # 移除所有article重新插入 news . articles . all ( ) . delete ( ) articles = Article . from_mp ( kwargs , news ) news . articles . bulk_create ( articles ) return news