3

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))
Hulk
  • 32,860
  • 62
  • 144
  • 215

2 Answers2

3

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

Steve Jalim
  • 11,989
  • 1
  • 37
  • 54
0

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

Tomasz Zieliński
  • 16,136
  • 7
  • 59
  • 83