1

I write

users = User.objects.filter(is_active=True, article_creator__in=articles)

And I get queryset

<QuerySet [<User: A>, <User: A>, <User: A>, <User: B>, <User: C>, <User: B>]>

How can to remove duplicate values. I need get this queryset

<QuerySet [<User: A>, <User: B>, <User: C>]>
rohit keshav
  • 305
  • 2
  • 16
unknown
  • 252
  • 3
  • 12
  • 37
  • 1
    try `filter(...).distinct()` – Aarif May 03 '19 at 15:32
  • 1
    This happens because of JOIN to articles. Turn this filter into `Exists()`. Btw, this filter definition `article_creator__in=articles` looks like a mistake or badly named variable. Because list of `articles` (article ids) will be applied to `creators` (creator id). Which does not seem to be consistent. – Ivan Starostin May 03 '19 at 16:09

1 Answers1

2

You are looking for .distinct()

So your new query will look like -

users = User.objects.filter(is_active=True, article_creator__in=articles).distinct()

You might also want to check this answer out.

rohit keshav
  • 305
  • 2
  • 16