Another example python template, this time a bit more complicated and more useful. It produces a list of all the authors for a series. The list is stored in a composite column (#comp2) that shows in the book details "on separate lines", which requires the list be a comma-separated. To make that work the template converts commas in author names to semicolons then builds the comma-separated list. The authors are then sorted, which is why the template uses author_sort.
The template:
Code:
python:
def evaluate(book, db, globals, arguments, **kwargs):
if book.series is None:
return ''
ans = set()
for id_ in db.search_getting_ids(f'series:"={book.series}"', ''):
ans.update([v.strip() for v in db.new_api.field_for('author_sort', id_).split('&')])
return ', '.join(v.replace(',', ';') for v in sorted(ans))
The result in book details showing all authors for the series of the current book: