content_gallery.py 文件源码

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

项目:django-content-gallery 作者: Kemaweyan 项目源码 文件源码
def gallery_image_data(obj):
    """
    Returns data of the image related to the object.
    Used to construct previews.
    """
    # get the first image related to the object
    image = utils.get_first_image(obj)
    try:
        # get data related to the object if the image exists
        data = {
            'app_label': image.content_type.app_label,
            'content_type': image.content_type.model,
            'object_id': str(image.object_id)
        }
    except AttributeError:
        # set empty data if the image does not exist
        data = {}
    # return the image and data in JSON format
    data_json = json.dumps(data)
    return {
        'image': image,
        'data_image': html.escape(data_json)
    }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号