Quote:
Originally Posted by dunhill
I have a custom information column with this template, maybe you can adapt it and see if it works for you.
[...]
|
That is an excellent start.
Here is the converted template. It returns the maximum series index for the series of the book. Somehow the indenting was lost in @dunhill's post, which is corrected here.
Code:
python:
def evaluate(book, context):
db = context.db.new_api
# Count the books in the series. First get the series name
series = book.get('series')
if series:
# The book is in a series. Get all the books in that series
series_id = db.get_item_id('series', series, case_sensitive=True)
books = db.books_for_field('series', series_id)
# Get the highest series index
max_dex = -9999
for b in books:
ser = db.field_for('series_index', b)
if ser > max_dex:
max_dex = ser
# Convert the max index to a string.
x = str(int(max_dex) if max_dex.is_integer() else max_dex)
else:
x = ''
return x
This template could be used in a custom column but it might be too slow because it operates on all the books all the time. It can be used on demand in Action chains, possibly in a Single Field Edit action that operates on all the books in a series.