Class-based views clash get_context_data
|Reported by:||Evandro Myller||Owned by:||Tobias McNulty|
|Cc:||eMyller@…, Carlos Palol, Reinout van Rees, Danilo Bargen||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
One of the best advantages of class-based views is the possibility to use "mixins". So now I'm trying to have a view that lists some database objects and puts an ordinary search form in the page. All I expect to do is the following:
class MyView(ListView, FormView): model = Model template_name = 'my_template.html' paginate_by = 12 form_class = SearchForm
But the way Django generic views collects data for the context completely misses such goal. We have .get_context_data (among other methods) clashing, so we never get both form and object_list keys.
One suggestion I give is to let the views feed a
self.context_data dict, so it could be far easier to access/modify the context and we wouldn't have such problem.
Change History (20)
comment:9 Changed 5 years ago by
|Owner:||changed from nobody to Tobias McNulty|
|Status:||new → assigned|