質問

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.

役に立ちましたか?

解決

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]

他のヒント

I found this:

for link in links: link.schema()

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top