Is it possible to determine from a brain if the referenced object has a teaser/lead image associated without fetching the object?
I have asked a similar question (quite) some time ago.
I think the answer is NO.
With archetype I think it was possible, there was even an index, think it was 'hasLeadImage'.
Maybe one could index the width (and height) of the image on save and use those ?
PS: if you solve this, please share
In on project I created a custom indexer (storing a list of the paths of a referenced image in this case). So, it is difficult to get a good common solution for this, but relatively easy to make a custom one.
I use a "related leadimage" behavior to avoid storing a static image in the object itself. Was rather easy to implement. I've put it in a github gist - it is in a "works for me" state...
I ended up with a customer index (specific for our project):
from Acquisition import aq_inner from zope.interface import Interface from plone.indexer.decorator import indexer marker = object @indexer(Interface) def has_teaser_image(obj, **kw): obj = aq_inner(obj) if obj.portal_type in ['Image', 'File']: return False for name in ('image', 'teaser_image'): img = getattr(obj, name, object) if img is object: continue if img is not None: return True return False