本文整理匯總了Python中wagtail.images.models.AbstractImage方法的典型用法代碼示例。如果您正苦於以下問題:Python models.AbstractImage方法的具體用法?Python models.AbstractImage怎麽用?Python models.AbstractImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wagtail.images.models
的用法示例。
在下文中一共展示了models.AbstractImage方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_field_display_value
# 需要導入模塊: from wagtail.images import models [as 別名]
# 或者: from wagtail.images.models import AbstractImage [as 別名]
def get_field_display_value(self, field_name, field=None):
""" Return a display value for a field/attribute """
# First we check for a 'get_fieldname_display' property/method on
# the model, and return the value of that, if present.
val_funct = getattr(self.instance, 'get_%s_display' % field_name, None)
if val_funct is not None:
if callable(val_funct):
return val_funct()
return val_funct
# Now let's get the attribute value from the instance itself and see if
# we can render something useful. raises AttributeError appropriately.
val = getattr(self.instance, field_name)
if isinstance(val, models.Manager):
val = val.all()
if isinstance(val, models.QuerySet):
if val.exists():
return ', '.join(['%s' % obj for obj in val])
return self.model_admin.get_empty_value_display(field_name)
# wagtail.images might not be installed
try:
from wagtail.images.models import AbstractImage
if isinstance(val, AbstractImage):
# Render a rendition of the image
return self.get_image_field_display(field_name, field)
except RuntimeError:
pass
# wagtail.wagtaildocuments might not be installed
try:
from wagtail.documents.models import AbstractDocument
if isinstance(val, AbstractDocument):
# Render a link to the document
return self.get_document_field_display(field_name, field)
except RuntimeError:
pass
# Resort to returning the real value or 'empty value'
if val or val is False:
return val
return self.model_admin.get_empty_value_display(field_name)