calibre-web-companion/CalibreWebCompanion/library/context_processors.py

31 lines
1.4 KiB
Python
Raw Normal View History

from .models import Author, Tag, Publisher, Language, Rating, Series
2020-07-11 17:56:22 +00:00
from django.db.models import Count
2020-08-02 02:51:34 +00:00
import logging
2020-07-08 16:22:37 +00:00
2020-08-02 02:51:34 +00:00
logger = logging.getLogger(__name__)
2020-07-08 16:22:37 +00:00
def filters(request):
2020-07-11 17:56:22 +00:00
# unique_authors = Author.objects.all().order_by('sort')
# unique_tags = Tag.objects.all().order_by('name')
# unique_publishers = Publisher.objects.all().order_by('name')
# unique_ratings = Rating.objects.all().order_by('rating')
# unique_languages = Language.objects.all()
# unique_series = Series.objects.all().order_by('sort')
# unique_authors = Author.objects.annotate(num_books=Count('book')).order_by('sort')
unique_authors = Author.objects.only('name', "id").annotate(num_books=Count('book')).order_by('name')
unique_tags = Tag.objects.annotate(num_books=Count('book')).order_by('name')
unique_publishers = Publisher.objects.annotate(num_books=Count('book')).order_by('name')
unique_languages = Language.objects.annotate(num_books=Count('book')).order_by('rating')
unique_ratings = Rating.objects.annotate(num_books=Count('book'))
unique_series = Series.objects.annotate(num_books=Count('book')).order_by('sort')
2020-07-08 16:22:37 +00:00
return {
"unique_authors": unique_authors,
"unique_tags": unique_tags,
"unique_publishers": unique_publishers,
"unique_languages": unique_languages,
"unique_ratings": unique_ratings,
"unique_series": unique_series
}