django query eliminate duplicates

By : Hulk
Source: Stackoverflow.com
Question!

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


Answers

For the record - .distinct() has some caveeats described in its documentation: http://docs.djangoproject.com/en/dev/ref/models/querysets/#distinct



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