I have several ModelForm classes, each of which represents a different model. I would like to have a generic create function that loads the specified model form based on the URL parameter. Dynamic dynamic loading of the model can be obtained as follows:
model_name = 'TestModel'
m = get_model('AppLabel', model_name)
Does anyone know how I can achieve the same for ModelForms, something like:
modelform_name = 'TestModelForm'
f = get_form('AppLabel', modelform_name)
if f.is_valid():
...
I canβt think of a way to do this using common views - they need to pass a ModelForm, not just its name. If I get a model with get_model, then I pass it to the general view, it will display the form, but I can not exclude the model fields.
TIA for any advice
source
share