def get_photo_thumbnail_ url self if getattr self photo Если не пустое

1
2
3
4
5
6
7
8
def get_photo_thumbnail_url(self):
if getattr(self, 'photo'): # Если не пустое значение.
dir, file = os.path.split(getattr(self, 'photo'))
file_name, ext = os.path.splitext(file)
new_file_name = file_name + u'_thumbnail' + ext
path = os.path.join(dir, new_file_name)
return urlparse.urljoin(settings.MEDIA_URL, path).replace('\\', '/')
return ''