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)
}
content_gallery.py 文件源码
python
阅读 18
收藏 0
点赞 0
评论 0
评论列表
文章目录