Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannout use distinct on get_initial_queryset() #261

Open
nahux opened this issue Oct 30, 2023 · 0 comments
Open

Cannout use distinct on get_initial_queryset() #261

nahux opened this issue Oct 30, 2023 · 0 comments

Comments

@nahux
Copy link

nahux commented Oct 30, 2023

I have this code in my DataTableView implementation:

    def get_initial_queryset(self):
        # Patients Query (NP Exams)
        patients = PaymentOption.objects.filter(
            pt__user=self.request.user,
            deleted=False
        ).order_by("pt__pk", "-option_accepted", "-pk").distinct("pt__pk")

        return patients

I get this error:
image

It does not matter what I do with the order_by and distinct it will always fail.
I saw that it fails inside get_context_data() function of BaseDatatableView class the line:

self.ordering(qs)

Somehow I made it work by reimplementing the ordering method with the same code but changing the way the request params are retrieved. For example from:

request.REQUEST.get('iSortCol_%s' % i)

to

request.GET.get('iSortCol_%s' % i)

Seems like I'm missing something else but that's what I found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant