ReportView get_queryset Request parameter
Parthian opened this issue · 2 comments
I have admin.py code to show only rows relevant to a user.
def get_queryset(self, request):
qs = super().get_queryset(request)
adminuser = request.user
return qs if adminuser.is_superuser else qs.filter(user=adminuser.id)
I need to do the same in a Report. So trying this.
def get_queryset(self, request): # show only the users own employee record. Superuser can see all.
qs = super().get_queryset() # Can't pass in request without error about too many parameters.
adminuser = request.user
return qs if adminuser.is_superuser else qs.filter(user=adminuser.id)
But I see this error.
Django Version: | 4.2.3
TypeError
EmployeeList.get_queryset() missing 1 required positional argument: 'request'
/home/user/apps/project/env/lib/python3.10/site-packages/slick_reporting/views.py, line 328, in get_report_results
erp_framework.admin.base.get_report_view
Python v3.10.11
But if I change the following code to add request my Report appears and filtered by the active user as expected. Great.
def get(self, request, *args, **kwargs):
form_class = self.get_form_class()
self.form = self.get_form(form_class)
if self.form.is_valid():
report_data = self.get_report_results(request) # Request added Line 162
And
def get_report_results(self, request, for_print=False): # Request added Line 322
"""
Gets the reports Data, and, its meta data used by datatables.net and highcharts
:return: JsonResponse
"""
queryset = self.get_queryset(request) # Request added Line 328
This may be a Slick Reporting bug and seems linked to this.
RamezIssac/django-slick-reporting#31 (comment)
Thanks.
Hello
The ReportView is a class based view, so in get_queryset
you need to access the request via the self.request .
Ah, that did the trick.