From afe50e464d76690fc1fa7c6d72c0d6d7e743a527 Mon Sep 17 00:00:00 2001 From: Gitea Date: Wed, 29 Apr 2020 02:15:31 +0000 Subject: adding stuff from live server --- app/books/models.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'app/books') diff --git a/app/books/models.py b/app/books/models.py index 8e8b485..eafa9be 100644 --- a/app/books/models.py +++ b/app/books/models.py @@ -94,11 +94,12 @@ class Book(models.Model): @receiver(post_save, sender=Book) def post_save_events(sender, update_fields, created, instance, **kwargs): - base_path = "%s/%s/" % (settings.MEDIA_ROOT, "/".join(str(i) for i in instance.image.name.split('/')[:-1])) - filename, file_extension = os.path.splitext(instance.image.path) - img = Image.open(instance.image.path) - resize_image(img, None, 160, 78, base_path, "%s_tn%s" % (filename.split('/')[-1], file_extension)) - resize_image(img, None, 650, 78, base_path, "%s_small%s" % (filename.split('/')[-1], file_extension)) + if instance.image: + base_path = "%s/%s/" % (settings.MEDIA_ROOT, "/".join(str(i) for i in instance.image.name.split('/')[:-1])) + filename, file_extension = os.path.splitext(instance.image.path) + img = Image.open(instance.image.path) + resize_image(img, None, 160, 78, base_path, "%s_tn%s" % (filename.split('/')[-1], file_extension)) + resize_image(img, None, 650, 78, base_path, "%s_small%s" % (filename.split('/')[-1], file_extension)) class BookHighlight(models.Model): -- cgit v1.2.3-70-g09d2