本文整理匯總了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