# Path: apps/images/models/db.py
# class Image(ImageAbstractModel):
#     description = models.CharField(max_length=255, blank=True)
#     is_cover = models.BooleanField(default=False)
# 
#     def __str__(self):
#         return self.description
# 
#     class Meta(ImageAbstractModel.Meta):
#         db_table = "generic_image"
# 
#     @cached_property
#     def thumb(self):
#         return self.resize_image()
# 
#     def resize_image(self, size=128):
#         _img_url = f"/upload/{size}/{self.file.name}"
#         if not debug:
#             _img_url = f"https://image.jiaxin.im{_img_url}"
#         return _img_url
# 
# Path: apps/ext/render/md.py



from urllib.parse import urlparse
from django.conf import settings
from django.contrib.contenttypes.fields import GenericRelation
from django.urls import reverse
from django.db import models
from django.utils import timezone
from django.utils.functional import cached_property
from django.utils.html import strip_tags
from django.utils.translation import ugettext_lazy as _
from django_extensions.db import fields
from model_utils import Choices
from model_utils.fields import StatusField, MonitorField
from taggit.managers import TaggableManager
from apps.images.models import Image
from apps.ext.render.md import md
        _("status"), choices_name="STATUS", default=STATUS.draft
    )
    content = models.TextField(blank=True, null=True)
    origin_link = models.URLField(
        _("origin_link"), max_length=255, null=True, unique=True
    )
    created_at = models.DateTimeField(
        default=timezone.now, db_index=True, editable=False
    )
    published_at = MonitorField(monitor="status", when=["published"])

    tags = TaggableManager(blank=True)

    images = GenericRelation(Image, related_query_name="images")

    objects = TutorialManager()

    class Meta:
        ordering = ["-published_at"]
        verbose_name = _("tutorial")
        verbose_name_plural = _("tutorial")

    def __str__(self):
        return f"{self.title}"

    def get_absolute_url(self) -> str:
        return f"https://jiaxin.im/tutorials/{self.slug}/"

    def render_markdown(self):
        html = md.convert(self.content)

# Path: apps/images/models/db.py
# class Image(ImageAbstractModel):
#     description = models.CharField(max_length=255, blank=True)
#     is_cover = models.BooleanField(default=False)
# 
#     def __str__(self):
#         return self.description
# 
#     class Meta(ImageAbstractModel.Meta):
#         db_table = "generic_image"
# 
#     @cached_property
#     def thumb(self):
#         return self.resize_image()
# 
#     def resize_image(self, size=128):
#         _img_url = f"/upload/{size}/{self.file.name}"
#         if not debug:
#             _img_url = f"https://image.jiaxin.im{_img_url}"
#         return _img_url
# 
# Path: apps/ext/render/md.py



# Path: apps/tutorials/models.py
from urllib.parse import urlparse
from django.conf import settings
from django.contrib.contenttypes.fields import GenericRelation
from django.urls import reverse
from django.db import models
from django.utils import timezone
from django.utils.functional import cached_property
from django.utils.html import strip_tags
from django.utils.translation import ugettext_lazy as _
from django_extensions.db import fields
from model_utils import Choices
from model_utils.fields import StatusField, MonitorField
from taggit.managers import TaggableManager
from apps.images.models import Image
from apps.ext.render.md import md

        _("status"), choices_name="STATUS", default=STATUS.draft
    )
    content = models.TextField(blank=True, null=True)
    origin_link = models.URLField(
        _("origin_link"), max_length=255, null=True, unique=True
    )
    created_at = models.DateTimeField(
        default=timezone.now, db_index=True, editable=False
    )
    published_at = MonitorField(monitor="status", when=["published"])

    tags = TaggableManager(blank=True)

    images = GenericRelation(Image, related_query_name="images")

    objects = TutorialManager()

    class Meta:
        ordering = ["-published_at"]
        verbose_name = _("tutorial")
        verbose_name_plural = _("tutorial")

    def __str__(self):
        return f"{self.title}"

    def get_absolute_url(self) -> str:
        return f"https://jiaxin.im/tutorials/{self.slug}/"

    def render_markdown(self):
        html = md.convert(self.content)

        return html, md.toc