You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am searching for a similar solution as well. I need to pass additional context to the filter class.
In my case I use django rest framework.
What I can suggest is to add context attribute to the filter class which can be passed by a get_filter_context method in the view. Pretty similar to how context is passed to the serializer - http://www.django-rest-framework.org/api-guide/serializers/#including-extra-context
to show the specific possible choices of a dataset I need to pass an additional parameter (here my_variable) form the views.py to filters.py:
views.py:
my_variable= 123
f = CompanyDataFilter(queryset=CompanyDataView.objects.using('extern_db').filter(company_id=primary))
filters.py
class CompanyDataFilter(django_filters.FilterSet):
....
sector = django_filters.ModelChoiceFilter(queryset=CompanyDataView.objects.values_list('sector', flat=True).using('extern_db').distinct().filter(company_id=my_variable),empty_label='Sector', help_text='Search Sector')
....
but I have no idea how to manage it to pass my_variable from the views.py to the filters.py
Any idea?
Thanks a lot in advance!
The text was updated successfully, but these errors were encountered: