Quote:
Originally Posted by chaley
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.
|





This is fantastic, thank you so much.
I added an empty book to the Jack Reacher series and calibre immediately populated the column for that book with the maximum index number. There was no lag (1,350 books)
After a re-start all books in the series were updated. When I deleted the empty book and restarted calibre, the field automatically updated again
Thank you to everyone who has help me with my query