Closed sainak closed 3 years ago
Hey @sainAk, what you probably want here is the .distinct()
clause. DjangoQL doesn't add it for you because it cannot decide automatically whether its needed. However, you can add it yourself to the resulting queryset produced by DjangoQL. For example, if you're using Django admin integration:
@admin.register(Car)
class CarAdmin(DjangoQLSearchMixin, admin.ModelAdmin):
def get_search_results(self, request, queryset, search_term):
qs, use_distinct = super().get_search_results(
request,
queryset,
search_term,
)
return qs, True # always return use_distinct=True
Thanks @stebunovd it works, but passing self
in super().get_search_results()
will throw a type error so just use *args
or remove the self
keyword.
yep - my bad, I didn't test it. I edited the comment above to fix that
My model structure:
objects:
So when I lookup for
tyres.name ~ "tyre"
in the CarAdmin I get 4 results of the same car. I wanted to know if it is possible to filter out duplicate results on admin.