]> git.parisson.com Git - mezzo.git/commitdiff
Add thumbs to orga list admin
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Mon, 3 Oct 2016 11:20:51 +0000 (13:20 +0200)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Mon, 3 Oct 2016 11:20:51 +0000 (13:20 +0200)
app/organization/core/models.py
app/organization/network/admin.py
app/organization/network/models.py

index e66d1e5977a5df39ede4536291d44f75b3c74c78..abd98b7a6c92db061b5a40cd4067087a8953907e 100644 (file)
@@ -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 "<img src='%s%s'>" % (settings.MEDIA_URL, thumb_url)
+    admin_thumb.allow_tags = True
+    admin_thumb.short_description = ""
index a3e1c019a925c2973d5a24abeb290be5114d141b..939481b3eb8d11223855a4a34d14263af3841587 100644 (file)
@@ -45,7 +45,7 @@ class OrganizationAdmin(BaseTranslationModelAdmin):
                 OrganizationVideoInline,
                 OrganizationBlockInline,
                 OrganizationLinkInline ]
-
+    list_display = ['name', 'admin_thumb']
 
 class DepartmentPageAdmin(PageAdmin):
 
index 8408ef6c81e1284e38f906fc7c1f65f26df5e9ba..8423618a3edb73ad8004812b709da8a734bf8c66 100644 (file)
@@ -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',]