I have a generic class-based view derived from ListView
. The view should interact with a form declared in forms.py
to filter the objects_list via a GET query and, also, modify the context (if you're interested in why I'd like to do that, check my previous question).
This means I need an instance of the form (form = MyForm(request.GET)
) both in the get_queryset
and get_context_data
methods.
This solution is not acceptable since it is a violation of this coding principle and assumes that get_queryset
will always gets called first (which may not be the case in future versions of Django).
Example:
def get_queryset(self):
self.form = MyForm(self.request.GET)
This solution is not acceptable since it uses the raw GET arguments while we'd like to harness the full potential of the form automatic parsing/validation.
Example:
def get_queryset(self):
a_form_field = self.kwargs["a_form_field"]
Is this possible to do without violating any good design principle?