Django-taggit similar_objects(): how to specify a model in the queryset

I use django-taggit on my site across several applications. The package uses a generic foreign key (by default), which allows it to work with many models, which is very convenient when working with tags and displaying different objects filtered by certain tags. But this default behaviour doesn't satisfy me when I try to find similar objects for example:

# news/views.py
class NewsDetailView(TagMixin, FormMixin, DetailView):
    model = News
    ...
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        related_items = self.object.tags.similar_objects()[:4]
        context['related_items'] = related_items
        return context

In this case, I want to select similar news, but instead I get similar objects of all types, including articles or shop goods. Please tell me how can I specify my model in this command:

related_items = self.object.tags.similar_objects()[:4]

I want it to be News only.

Back to Top