+ def estimated_costs(self, obj):
+ costs = Counter()
+ for book in obj.book_set.all():
+ for k, v in book.get_estimated_costs().items():
+ costs[k] += v or 0
+
+ for author in obj.author_set.all():
+ for book in author.book_set.all():
+ for k, v in book.get_estimated_costs().items():
+ costs[k] += v or 0
+ for book in author.translated_book_set.all():
+ for k, v in book.get_estimated_costs().items():
+ costs[k] += v or 0
+
+ return "\n".join(
+ "{}: {} zł".format(
+ work_type.name,
+ cost or '—'
+ )
+ for work_type, cost in costs.items()
+ )
+