本文整理汇总了Python中photologue.models.Photo.get_avaliable_title方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.get_avaliable_title方法的具体用法?Python Photo.get_avaliable_title怎么用?Python Photo.get_avaliable_title使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类photologue.models.Photo
的用法示例。
在下文中一共展示了Photo.get_avaliable_title方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clean_photo
# 需要导入模块: from photologue.models import Photo [as 别名]
# 或者: from photologue.models.Photo import get_avaliable_title [as 别名]
def clean_photo(self):
cleaned_data = self.cleaned_data
cleaned_data['id_photo'] = self.data['id_photo']
photo = cleaned_data.get('photo')
if isinstance(photo, long):
try:
cleaned_data['photo'] = Photo.objects.get(pk=photo)
except Photo.DoesNotExist:
raise forms.ValidationError(_('Photo does not exist'))
elif isinstance(photo, InMemoryUploadedFile):
new_photo = Photo(title=photo.name, image=photo, is_gallery_thumbnail=True)
cleaned_data['photo'] = new_photo
try:
new_photo.save()
except IntegrityError:
new_photo.title = new_photo.get_avaliable_title()
new_photo.save()
return cleaned_data['photo']