Closed craftycorvid closed 7 years ago
Why don't you just override update_widget_rendering_context()
in the corresponding field class?
Because widgets don't always need corresponding field classes. In my use case I am creating a widget that works with ModelMultipleChoiceField, but I have no need to modify the ModelMultipleChoiceField.
More importantly, the current implementation is relying on an implementation detail. It just so happens that Django currently does not override get_context on any of their field classes. If, say, TextInput needed a get_context() method then the current implementation would break.
OK, got it. I will look for a working solution.
Actually, I misspoke. Looking over django/forms/widgets.py, plenty of Widgets are overriding get_context. For example, the get_context method on Select is skipped by the current implementation.
Is there something you don't like about my pull request? It does solve the issue and I have not seen it break anything in my testing thus far.
Here's another possible solution for #297 that won't skip the get_context method of the current widget class. This seem cleaner than the previous solution and should avoid any potential infinite loops.