How to filter related objects after a search in django-filter?

I use django-filter on my website to search for books. The filter includes the following fields: book genre, language in which the book is written, publication date, and search field. The search looks for multiple fields in the database, including the book title, authors of the book, etc. The filter works fine, but I don't understand how to make it so that when I search for a book after getting the search result, I will remove the fields that are not related to the result (i.e. genres, language) For example, I want to find books about Harry Potter. After I entered the book title in the search result and associated fields, that is, I see that the site is not related to the book about Harry Potter Chinese (it was removed after the result). The second question - is it possible to make so that after the search I would see how many objects are in each field? That is, if I entered Harry Potter in the search and got a result, I see that there are 5 objects in English.

models.py

class Book(models.Model):
   name = models.CharField(max_length=255)
   author = models.ForeignKey(
        "Authors",
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
    )
   subject = TreeManyToManyField("Subject")
   published_date = models.DateField(blank=True, null=True)
   language = models.ForeignKey(
        "Language", on_delete=models.SET_NULL, null=True)

class Subject(MPTTModel):
   name = models.CharField(
        max_length=1000,
        unique=True,
    )

class Language(models.Model):
    name = models.CharField(
        max_length=255,
        unique=True,
    )

class Authors(models.Model):
       name = models.CharField(
        max_length=255,
        unique=True,
        )

filters.py

class BookFilter(django_filters.FilterSet):
  search = django_filters.CharFilter(
        method="my_custom_filter",
        widget=TextInput(
            attrs={
                "class": "form-control",
                "placeholder": _("Type to search"),
            }
        ),
    )
    language = django_filters.ModelMultipleChoiceFilter(
        field_name="language",
        queryset=Language.objects.order_by("name"),
        widget=forms.CheckboxSelectMultiple(),
    )
    subject = django_filters.ModelMultipleChoiceFilter(
        field_name="subject",
        queryset=Subject.objects.all(),
        widget=autocomplete.ModelSelect2Multiple(}
        ),
    )
    class Meta:
        model = Book
        fields = {
            "subject",
            "language",
            "published_date",
        }

    def my_custom_filter(self, queryset, name, value):
        q = value
        return (
            queryset.annotate(
                rank=SearchRank(vector, q),
                similarity=TrigramSimilarity("title", q)
                + similarity=TrigramSimilarity("author", q)
)

views.py

def BookListView(request):
    book = Book.objects.all()
    filter = BookFilter(request.GET, queryset=book)
    context = {
        "filter": filter,
        "book": book,
    }
    return render(request, "book.html", context)

book.html

{% extends "base.html" %}

{% block content %}
    <form method="get">
        {{ filter.form.as_p }}
        <input type="submit" />
    </form>
    {% for obj in filter.qs %}
        {{ obj.name }} - ${{ obj.price }}<br />
    {% endfor %}
{% endblock %}
Back to Top