Django CreateView Form POST Call Sequence
For some reason, I cannot find a straightforward call sequence for when your POST a form in Django. I currently am stuck with a form that is failing. I suspect it has something to do with the half-implemented MultiSelect Custom Widget I am trying to implement, but without knowing the sequence of methods it is hard for me to know where to begin debugging.
A bit of context: this sequence will be based on using a CreateView subclass. It is routed from urls.py via a CreateView.as_view() call. With that in mind, here we go.
Django Form POST call sequence: 1. CreateView.init() 1. CreateView.getformkwargs() 1. Form.init() 1. Form.isvalid() 1. Form.clean() 1. CreateView.getcontext_data()
After the last call to getcontextdata() it routes back to the Form and calls my overridden subwidget method (due to a “bug” Django 3+) for my multiselect custom widget.
For posterity's sake, I have also performed a quick check against the GET sequence.
Django Form GET call sequence: 1. CreateView.init() 1. CreateView.getcontextdata() 1. CreateView.getformkwargs() 1. Form.init() 1. MultiWidget. subwidgets() 1. MultiWidget.decompress()
Now, the current issue I am having is because I am unsure how my custom widget's decompress is mapping the bound model to the HTML select option. Subsequently, I am unsure how the POST command is actually re-binding to model for saving when calling the form.savem2m() method.