djongo
djongo copied to clipboard
Distinct: NotSupportedError
One line description of the issue
so, i have repeated elements and i'm trying to use distinct to filter then by one field. But i'm getting "DISTINCT ON fields is not supported by this database backend", any thoughts?
Python script
return object_list.order_by('name').distinct('registration')
#### Traceback
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
34. response = get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
126. response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
124. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py" in dispatch
88. return handler(request, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/views/generic/list.py" in get
157. context = self.get_context_data()
File "/code/portal/views.py" in get_context_data
77. context = super().get_context_data(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/views/generic/list.py" in get_context_data
119. paginator, page, queryset, is_paginated = self.paginate_queryset(queryset, page_size)
File "/usr/local/lib/python3.6/site-packages/django/views/generic/list.py" in paginate_queryset
69. page = paginator.page(page_number)
File "/usr/local/lib/python3.6/site-packages/django/core/paginator.py" in page
67. number = self.validate_number(number)
File "/usr/local/lib/python3.6/site-packages/django/core/paginator.py" in validate_number
45. if number > self.num_pages:
File "/usr/local/lib/python3.6/site-packages/django/utils/functional.py" in __get__
37. res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.6/site-packages/django/core/paginator.py" in num_pages
97. if self.count == 0 and not self.allow_empty_first_page:
File "/usr/local/lib/python3.6/site-packages/django/utils/functional.py" in __get__
37. res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.6/site-packages/django/core/paginator.py" in count
87. return self.object_list.count()
File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py" in count
383. return self.query.get_count(using=self.db)
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py" in get_count
498. number = obj.get_aggregation(using, ['__count'])['__count']
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py" in get_aggregation
466. outer_query.add_subquery(inner_query, using)
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/subqueries.py" in add_subquery
193. self.subquery, self.sub_params = query.get_compiler(using).as_sql(with_col_aliases=True)
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in as_sql
472. distinct_params,
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/operations.py" in distinct_sql
171. raise NotSupportedError('DISTINCT ON fields is not supported by this database backend')
Exception Type: NotSupportedError at /recursos-humanos/lista/
Exception Value: DISTINCT ON fields is not supported by this database backend
I am having an issue similar to this one. Did you ever find a solution to this?
Any update on this? Please provide any solution/workaround.
I need help! Same issue here
Pymongo support distinct - this feature should be added.