# Path: backend/photos/models/photo/model.py
# class Photo(TimeStampMixin, NameSlugMixin, OrderMixin, IsEnabledMixin):
#     class Meta:
#         verbose_name = _('photo')
#         verbose_name_plural = _('photos')
#         app_label = 'photos'
#         default_related_name = 'photos'
#         ordering = ('order',)
# 
#     image = FileBrowseField(verbose_name=_('image'), directory='photos/', extensions=[".jpg", ".png"], max_length=500)
#     categories = models.ManyToManyField(to=Category, verbose_name=_('category'))


from ordered_model.admin import OrderedModelAdmin
from filebrowser.settings import ADMIN_THUMBNAIL
from django.utils.translation import ugettext_lazy as _
from django.contrib.admin import StackedInline
from .model import Photo


class PhotoAdmin(OrderedModelAdmin):
    list_display = ('as_rendered',  'is_enabled', 'name', 'slug',
        'move_up_down_links', 'order', 'created', 'updated')
    list_filter = ('is_enabled', 'categories')
    list_editable = ('name', 'slug', 'is_enabled')
    date_hierarchy = 'modified'

    def as_rendered(self, obj):
        if obj.image and obj.image.filetype == "Image":
            image_style = "color: #fff; height: 240px; width: 320px; \
                display: flex; align-items: center; align-content: center; \
                background: left top url('%s') no-repeat; position: relative;" \
                % obj.image.version_generate(ADMIN_THUMBNAIL).url
            span_style = "background: rgba(0, 0, 0, .3); color: #fff; \

# Path: backend/photos/models/photo/model.py
# class Photo(TimeStampMixin, NameSlugMixin, OrderMixin, IsEnabledMixin):
#     class Meta:
#         verbose_name = _('photo')
#         verbose_name_plural = _('photos')
#         app_label = 'photos'
#         default_related_name = 'photos'
#         ordering = ('order',)
# 
#     image = FileBrowseField(verbose_name=_('image'), directory='photos/', extensions=[".jpg", ".png"], max_length=500)
#     categories = models.ManyToManyField(to=Category, verbose_name=_('category'))


# Path: backend/photos/models/photo/admin.py
from ordered_model.admin import OrderedModelAdmin
from filebrowser.settings import ADMIN_THUMBNAIL
from django.utils.translation import ugettext_lazy as _
from django.contrib.admin import StackedInline
from .model import Photo



class PhotoAdmin(OrderedModelAdmin):
    list_display = ('as_rendered',  'is_enabled', 'name', 'slug',
        'move_up_down_links', 'order', 'created', 'updated')
    list_filter = ('is_enabled', 'categories')
    list_editable = ('name', 'slug', 'is_enabled')
    date_hierarchy = 'modified'

    def as_rendered(self, obj):
        if obj.image and obj.image.filetype == "Image":
            image_style = "color: #fff; height: 240px; width: 320px; \
                display: flex; align-items: center; align-content: center; \
                background: left top url('%s') no-repeat; position: relative;" \
                % obj.image.version_generate(ADMIN_THUMBNAIL).url
            span_style = "background: rgba(0, 0, 0, .3); color: #fff; \

                padding: 1em; border-radius: 0 .5em .5em 0;"