django query eliminate duplicates

By : Hulk

In the following query how to eliminate the duplicates,

d_query = Profile.objects.filter(company="12") 

search_string ="Tom"
if search_string != "":
   d_query = d_query.filter(Q(profiles__name__icontains=search_string) |   Q(first_name__icontains=search_string)| Q(last_name__icontains=search_string))
By : Hulk


For the record - .distinct() has some caveeats described in its documentation:

Assuming you mean you want to avoid getting back the same record more than once, you can just add .distinct() to your queryset before evaluating it

This video can help you solving your question :)
By: admin