alternate way to find series with missing books to use in series add drop-down - fixes issue with a new series with no bsl yet not showin in list
This commit is contained in:
18
series.py
18
series.py
@@ -48,11 +48,21 @@ def CalcAvgRating(sid):
|
||||
return rating
|
||||
|
||||
def ListOfSeriesWithMissingBooks():
|
||||
with db.engine.connect() as conn:
|
||||
res=conn.exec_driver_sql( "select id, title, num_books, count from ( select s.id, s.title, s.num_books, count(bsl.book_id) from series s left outer join book_series_link bsl on bsl.series_id=s.id where bsl.book_num is not null group by s.id) as foo where num_books > count")
|
||||
from main import Book_Series_Link
|
||||
|
||||
rows = Series.query.outerjoin(Book_Series_Link).add_columns(Series.id,Series.title,Series.num_books,Book_Series_Link.book_num).order_by(Series.id,Book_Series_Link.book_num).all()
|
||||
tmp=[]
|
||||
for row in res:
|
||||
tmp.append({'id': row[0], 'title': row[1]})
|
||||
tots={}
|
||||
for row in rows:
|
||||
if row.id not in tots:
|
||||
tots[row.id]={ 'title': row.title, 'num_books': row.num_books, 'count': 0 }
|
||||
if row.book_num is None:
|
||||
continue
|
||||
else:
|
||||
tots[row.id]['count'] += 1
|
||||
for idx in tots:
|
||||
if tots[idx]['num_books'] > tots[idx]['count']:
|
||||
tmp.append( { 'id': idx, 'title': tots[idx]['title'] } )
|
||||
return tmp
|
||||
|
||||
################################################################################
|
||||
|
||||
Reference in New Issue
Block a user