Pregunta

How to show all keys for items that I get in a catalog search?

links = self.catalog(portal_path='Link')
for link in links:
    for value in link:
        print value

With this code I can show all values, but I don't know how to show the keys.

¿Fue útil?

Solución

The ZCatalog does not return dictionaries. It returns a sequence of result objects (called Catalog Brains, because you can give them smarts. Long historical story).

So you loop over them, and each object has attributes for each metadata column you defined in the catalog:

links = self.catalog(portal_path='Link')
for link in links:
    print link.Title

If you need to dynamically loop over the available attributes, use .schema() for the keys:

for link in links:
    for key in link.schema():
        print link[attr]

Otros consejos

I found this:

for link in links: link.schema()

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top