View Single Post
Old 05-10-2025, 01:51 PM   #11
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,471
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by dunhill View Post
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.

Last edited by chaley; 05-10-2025 at 01:58 PM. Reason: Faster template
chaley is offline   Reply With Quote