本文整理汇总了Python中photos.models.Photo.to_json方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.to_json方法的具体用法?Python Photo.to_json怎么用?Python Photo.to_json使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类photos.models.Photo
的用法示例。
在下文中一共展示了Photo.to_json方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from photos.models import Photo [as 别名]
# 或者: from photos.models.Photo import to_json [as 别名]
def create(self, request, raw=False, **kwargs):
""" Uploads a new photo. """
title = request.CLEANED.get('title', '')
description = request.CLEANED.get('description', '')
if request.CLEANED['url']:
photo = get_picture_from_url(request.CLEANED['url'])
elif request.CLEANED['file64']:
photo = request.CLEANED['photo']
else:
if request.CLEANED['file']:
uploaded_file = request.CLEANED['file']
format = request.CLEANED['format']
photo = Photo(user=request.user, title=title, description=description)
photo.image.save("%s.%s" % (uuid.uuid4(), format), uploaded_file)
photo.save()
uploaded_file.close()
return photo.to_json(request=request, detail=request.CLEANED['detail']) if not raw else photo