From: Guillaume Pellerin Date: Mon, 3 Oct 2016 11:20:51 +0000 (+0200) Subject: Add thumbs to orga list admin X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=2c506e3fdc6ab33e2380f339a8562cc43fc6d02e;p=mezzo.git Add thumbs to orga list admin --- diff --git a/app/organization/core/models.py b/app/organization/core/models.py index e66d1e59..abd98b7a 100644 --- a/app/organization/core/models.py +++ b/app/organization/core/models.py @@ -194,3 +194,28 @@ class Period(models.Model): class Meta: abstract = True + + +class AdminThumbRelatedMixin(object): + """ + Provides a thumbnail method on models for admin classes to + reference in the ``list_display`` definition. + """ + + admin_thumb_type = None + + def admin_thumb(self): + thumb = "" + if self.admin_thumb_type: + images = self.images.filter(type=self.admin_thumb_type) + if images: + thumb = images[0].file + if not thumb: + return "" + from mezzanine.conf import settings + from mezzanine.core.templatetags.mezzanine_tags import thumbnail + x, y = settings.ADMIN_THUMB_SIZE.split('x') + thumb_url = thumbnail(thumb, x, y) + return "" % (settings.MEDIA_URL, thumb_url) + admin_thumb.allow_tags = True + admin_thumb.short_description = "" diff --git a/app/organization/network/admin.py b/app/organization/network/admin.py index a3e1c019..939481b3 100644 --- a/app/organization/network/admin.py +++ b/app/organization/network/admin.py @@ -45,7 +45,7 @@ class OrganizationAdmin(BaseTranslationModelAdmin): OrganizationVideoInline, OrganizationBlockInline, OrganizationLinkInline ] - + list_display = ['name', 'admin_thumb'] class DepartmentPageAdmin(PageAdmin): diff --git a/app/organization/network/models.py b/app/organization/network/models.py index 8408ef6c..8423618a 100644 --- a/app/organization/network/models.py +++ b/app/organization/network/models.py @@ -71,12 +71,14 @@ class Address(models.Model): abstract = True -class Organization(Named, Address, URL): +class Organization(Named, Address, URL, AdminThumbRelatedMixin): """(Organization description)""" type = models.ForeignKey('OrganizationType', verbose_name=_('organization type'), blank=True, null=True, on_delete=models.SET_NULL) is_on_map = models.BooleanField(_('is on map'), default=True) + admin_thumb_type = 'logo' + class Meta: verbose_name = _('organization') ordering = ['name',]