[Zope] How do I get a uniqueValuesFor() a subset of the catalog?
Dieter Maurer
dieter@handshake.de
Mon, 29 Jan 2001 20:33:54 +0100 (CET)
Philip Aylesworth writes:
> I am trying to get a list of unique values for one particular meta_type.
> The uniqueValuesFor() works great but is there a way to get unique
> values for a subset of data such as meta_type='car' then
> uniqueValuesFor('make') would list the makes of cars but not of
> toasters?
The "uniqueValuesFor" is an artifact of the way indexes are
implemented: a mappings. They map index terms to lists of
objects indexed under the corresponding term.
Most mappings have a "keys()" method. It gives the
"uniqueValuesFor".
That said, if you want to have "uniqueValuesFor" a subset
of the catalog, you cannot use this "keys()" method.
You must do it yourself:
Select the objects you want, build a dictionary mapping
the attribute you are interested in to something (say 1)
and use the "keys()" method of this dict.
Something like 3 to 5 lines in a PythonScript.
Dieter