python - Sum if in Django ORM -
i have 2 models: publisher , book.
i retrieving publishers with
publisher.objects.filter(name="a").annotate(total_pages=sum('books__num_pages')) but interested in total sum of number of pages books written in 2014.
i not familiar options create sumif in django. how others solve problem?
i think there should possibility like
sum('books__num_pages', where={'year': 2014}) or that.
books_num_pages = books.objects.filter(publisher__name='a', year=2014).aggregate(sum('num_pages'))
python django django-models django-forms django-views
No comments:
Post a Comment