0

I'm using django-datatable-view (https://github.com/pivotal-energy-solutions/django-datatable-view) and I'd like to dynamically pass URL parameters to the DatatableView and filter get_queryset() based on those URL Parameters.

Here is an example URL:

http://<my_url>/?id=1 or http://<my_url>/?level=0 or whatever

views.py

    class MyDatatableListView(DatatableView):
        ...
        def get_queryset(self):
            queryset = super(MyDatatableListView, self).get_queryset()
            return queryset.filter(**self.request.GET.dict())
        ...

Of course, request.GET retrieves URL parameters in ListView and works perfectly, however, it appears that DatatableView is overriding self.request.GET. Is there a way to retrieve URL parameters in DatatableView?

btal
  • 81
  • 6
  • According to [the docs][1], DatatableView receives AJAX requests to define the table sorting, searches or page number. That means your GET parameters will be overriden by the AJAX requests. Why don't you try capturing the url? [1]: http://django-datatable-view.readthedocs.io/en/latest/topics/interaction-model.html – Marco Lavagnino Dec 27 '16 at 20:44
  • I can capture request.path which doesn't have the URL parameters attached, and I can assign a variable and get parameters that way. For example http:///?query=[level:0,id:5] then convert that to a dict for filtering get_queryset but it just isn't as clean. Considering just building my own very basic DatatableView ListView since so I can capture request.GET like normal. In the source code there is this query_config context variable but I can't figure out how to leverage it and I don't see any documentation for it. – btal Dec 27 '16 at 21:07
  • i was thinking of something like `http:///(id)/(someParameter)/`, you could capture `id` and `someParameter` from request.path – Marco Lavagnino Dec 27 '16 at 22:30
  • Yes sir, I have thought about that as well, the challenge is that I'm passing over 100 models, between several projects that I plan to pass over 100 models over a single pattern and each model has different fields that I want to filter. If you're interested, see this question about the pattern: http://stackoverflow.com/questions/41342813/dynamically-pass-app-label-and-model-name-to-the-url-in-python-django – btal Dec 28 '16 at 09:02
  • It won't let me edit that last comment so let me to try that again. I am passing over 100 models, between several projects over a single pattern and each model have different fields that I want to filter. This pattern is described here: http://stackoverflow.com/questions/41342813/dynamically-pass-app-label-and-model-name-to-the-url-in-python-django – btal Dec 28 '16 at 09:06

0 Answers0