我正在做一個項目,需要用戶照片上傳和創建相冊(如Facebook相冊),其中一個用戶可以上傳一個相冊中的多張照片,可以上傳多個相冊。如此搜索後,我發現django imagestore應用程序非常方便。但不幸的是我沒有找到任何示例礦石教程的imagestore.I在django非常新。需要關於這個應用程序的一些示例教程..你能否提出更好的方式來創建一個相冊?需要創建一個django相冊
這是我創建的相冊的方法 - 在這裏,我無法修復
def img_file_upload_path(instance, filename):
""" creates unique-Path & filename for upload """
ext = filename.split('.')[-1]
filename = "%s%s.%s" % ('img', instance.pk, ext)
return os.path.join(
'images','eventpic','original',
instance.event_id.channel_id.publisher.user.username,
instance.event_id.channel_id.channel_title,
instance.event_id.event_title,
filename
)
def formatted_img_file_upload_path(instance, filename):
""" creates unique-Path & filename for upload """
ext = filename.split('.')[-1]
filename = "%s%s.%s" % ('img', instance.pk, ext)
return os.path.join(
'images','eventpic','formatted',
instance.event_id.channel_id.publisher.user.username,
instance.event_id.channel_id.channel_title,
instance.event_id.event_title,
filename
)
def thumb_img_file_upload_path(instance, filename):
""" creates unique-Path & filename for upload """
ext = filename.split('.')[-1]
filename = "%s%s.%s" % ('img', instance.pk, ext)
return os.path.join(
'images','eventpic','thumb',
instance.event_id.channel_id.publisher.user.username,
instance.event_id.channel_id.channel_title,
instance.event_id.event_title,
filename
)
class Album(models.Model):
album_id = models.AutoField(primary_key=True)
event_id = models.ForeignKey(event_archive,db_column='event_id')
name = models.CharField(max_length=128)
summary = models.TextField()
date_created = models.DateTimeField(auto_now_add=True)
date_modified = models.DateTimeField(auto_now=True)
class Photo(models.Model):
image_id = models.AutoField(primary_key=True)
album = models.ForeignKey(Album,db_column='album_id')
title = models.CharField(max_length=255)
summary = models.TextField(blank=True, null=True)
date_created = models.DateTimeField(auto_now_add=True)
date_modified = models.DateTimeField(auto_now=True)
is_cover_photo = models.BooleanField()
original_image = models.ImageField(upload_to=img_file_upload_path)
def save(self):
if self.is_cover_photo:
other_cover_photo = Photo.objects.filter(album=self.album).filter(is_cover_photo = True)
for photo in other_cover_photo:
photo.is_cover_photo = False
photo.save()
filename = self.img_file_upload_path()
if not filename == '':
img = Image.open(filename)
if img.mode not in ("L", "RGB"):
img = img.convert("RGB")
img.resize((img.size[0], img.size[1]/2),Image.ANTIALIAS)
img.save(self.formatted_img_file_upload_path(),quality=90)
img.thumbnail((150,150), Image.ANTIALIAS)
img.save(self.thumb_img_file_upload_path(),quality=90)
super(Photo, self).save()
def delete(self):
filename = self.img_file_upload_path()
try:
os.remove(self.formatted_img_file_upload_path())
os.remove(self.thumb_img_file_upload_path())
except:
pass
super(Photo, self).delete()
def get_cover_photo(self):
if self.photo_set.filter(is_cover_photo=True).count() > 0:
return self.photo_set.filter(is_cover_photo=True)[0]
elif self.photo_set.all().count() > 0:
return self.photo_set.all()[0]
else:
return None
的錯誤是
filename = self.img_file_upload_path()
需要幫助修復error.Do你想辦法可以創建一個像photoalbum一樣的facebook嗎?或者我應該使用imagestore應用程序嗎?在這裏我想提到的是,我想保存格式化的圖像和拇指圖像保持上傳..需要您的專家審查和幫助。
安置自己的錯誤回溯。 – jdi
雖然我上傳照片submit..Exception類型在此之後eroor發生:\t AttributeError的 異常值:\t 「照片」對象有沒有屬性「img_file_upload_path」 – oxvoxic