diff --git a/boards/models/post/__init__.py b/boards/models/post/__init__.py --- a/boards/models/post/__init__.py +++ b/boards/models/post/__init__.py @@ -200,7 +200,12 @@ class Post(models.Model, Viewable): return self.get_view(need_op_data=True, *args, **kwargs) def get_first_image(self) -> Attachment: - return self.attachments.filter(mimetype__in=FILE_TYPES_IMAGE).earliest('id') + image = None + try: + image = self.attachments.filter(mimetype__in=FILE_TYPES_IMAGE).earliest('id') + except Attachment.DoesNotExist: + pass + return image def set_global_id(self, key_pair=None): """ diff --git a/boards/models/post/export.py b/boards/models/post/export.py --- a/boards/models/post/export.py +++ b/boards/models/post/export.py @@ -37,10 +37,10 @@ class JsonExporter(Exporter): 'title': post.title, 'text': post.get_raw_text(), } - if post.attachments.exists(): - post_image = post.get_first_image() + post_image = post.get_first_image() + if post_image: post_json['image'] = post_image.file.url - post_json['image_preview'] = post_image.get_preview_url() + post_json['image_preview'] = post_image.get_thumb_url() if include_last_update: post_json['bump_time'] = utils.datetime_to_epoch( post.get_thread().bump_time)