apps.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:wagtail-metadata-mixin 作者: bashu 项目源码 文件源码
def handle_blog_model(sender, instance, **kwargs):
    from wagtailmetadata.models import MetadataMixin

    sender = mixin(sender, [MetadataMixin])

    def get_meta_description(cls):
        return cls.search_description or truncatewords(cls.description, 20)

    sender.add_to_class('get_meta_description', get_meta_description)

    def get_meta_image(cls):
        if cls.header_image is not None:
            return cls.build_absolute_uri(
                cls.header_image.get_rendition('fill-800x450').url)
        return super(sender, cls).get_meta_image()

    sender.add_to_class('get_meta_image', get_meta_image)

    sender.object_type = "blog"

    sender._metadata = {
        'gplus_type': "Blog",
    }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号