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 = ""
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',]