Commit 10a00f0d88f8aa8a5178ee3f9938e843bad2fd34

Authored by cesar
1 parent 73018083

add render method

Showing 1 changed file with 9 additions and 1 deletions
1 1 from django.conf import settings
2 2 from django.db import models
  3 +from django.db.models.fields.files import FieldFile
3 4 from django.utils import timezone
  5 +from django.utils.html import format_html
4 6 from django.utils.translation import gettext_lazy as _
5 7
6 8 from .abstracts import (
... ... @@ -10,7 +12,13 @@ from .abstracts import (
10 12
11 13 class Comment(CommentAbstractModel):
12 14 # Sofisis add this field for support images as comment
13   - image = models.FileField(_('Image'), upload_to='comments/%Y/%m/', null=True, blank=True)
  15 + image: FieldFile = models.FileField(_('Image'), upload_to='comments/%Y/%m/', null=True, blank=True)
  16 +
  17 + def render_comment(self) -> str:
  18 + """ Render comment in html, include image if exists """
  19 + if self.image:
  20 + return format_html(self.comment + ' <img src="{url}"/>', url=self.image.url)
  21 + return self.comment
14 22
15 23 class Meta(CommentAbstractModel.Meta):
16 24 db_table = "django_comments"
... ...
Please register or login to post a comment