Skip to content

Cannout use distinct on get_initial_queryset() #261

@nahux

Description

@nahux

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions