# 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


from django.contrib import admin
from django.contrib.contenttypes.admin import GenericStackedInline
from apps.images.models import Image


class TutorialImageInlineAdmin(GenericStackedInline):
    model = Image
    fields = ["file", "description", "is_cover"]
    extra = 1


class TutorialAdmin(admin.ModelAdmin):
    list_display = ["slug", "title", "tag_string", "status", "published_at"]
    list_display_links = ["title"]
    list_filter = ["status"]

# 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/tutorials/admin/tutorial.py
from django.contrib import admin
from django.contrib.contenttypes.admin import GenericStackedInline
from apps.images.models import Image



class TutorialImageInlineAdmin(GenericStackedInline):
    model = Image
    fields = ["file", "description", "is_cover"]
    extra = 1


class TutorialAdmin(admin.ModelAdmin):
    list_display = ["slug", "title", "tag_string", "status", "published_at"]
    list_display_links = ["title"]
    list_filter = ["status"]

    list_editable = ["status"]