From d27f04dec4d1e61b40cd21daf8cf071287181f81 Mon Sep 17 00:00:00 2001 From: JJ Date: Mon, 9 Jun 2014 16:00:41 -0400 Subject: [PATCH] added '.distinct()' to result query on ModelJsonMixin to prevent duplicates --- django_select2/fields.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/django_select2/fields.py b/django_select2/fields.py index b1a6d94..60a4169 100644 --- a/django_select2/fields.py +++ b/django_select2/fields.py @@ -265,12 +265,12 @@ class ModelResultJsonMixin(object): if self.max_results: min_ = (page - 1) * self.max_results max_ = min_ + self.max_results + 1 # fetching one extra row to check if it has more rows. - res = list(qs.filter(*params['or'], **params['and'])[min_:max_]) + res = list(qs.filter(*params['or'], **params['and']).distinct()[min_:max_]) has_more = len(res) == (max_ - min_) if has_more: res = res[:-1] else: - res = list(qs.filter(*params['or'], **params['and'])) + res = list(qs.filter(*params['or'], **params['and']).distinct()) has_more = False res = [(getattr(obj, self.to_field_name), self.label_from_instance(obj), self.extra_data_from_instance(obj))