Filtering of objects which have one to many relation with another in template

Hello! My problem is next:

I have 3 classes:

Rubric, Report, ScienceEvent

And next relations:

One rubric - many reports
One event - many reports

Some words about Rubric:
Rubric has Charfield “name” with 3 possible values “chm”, “blg”, “plg” (chemistry, biology and etc.)
So, I have only 3 rubrics.

I want to pass event object in context for template
and then iterate reports of this event which relate to some rubric (for example “chm”)

So, I want something like that

{% for r in event.reports.which_rubric 'chm" %}

{% endfor %}

I can do this by writing 3 methods for ReportManager but it is bad style, I suppose
Or I can parse data in view and make list of reports which relate to this event and have rubruc “chm” but this is bad solution too for me

Or I can write custom filter like

{% for r in event.reports | which_rubric: 'chm" %}

{% endfor %}

What is the best solution?

Your best solution is to build your data structures in the view, and reserve use of the template for displaying the data. Templates aren’t designed to filter data - it should be filtered when preparing the context for that template.