[Fixed]-Can anyone please explain me the what are Django modelform_factory and modelformset_factory?

0πŸ‘

βœ…

There are multiple places, where you have automatically generated forms or formsets, the most visible is admin and Generic Class Views.

Every time you are working with HTML forms do add or modify data – you should use forms.Form. If you are working with the model – there is forms.ModelForm which is build on top of the Form – handling automatically declaration of fields, some validations and instance save. Then on top of this you have modelform_factory – which is generating on-demand ModelForm – so it is kind of shortcut to define default ModelForm for your model.

Similar, modelformset_factory is generating ModelFormSet to be used with one-to-many relations.

πŸ‘€Jerzyk

1πŸ‘

modelform_factory is a method to create forms in views , without defining form in forms.py file.

πŸ‘€Neeraj

Leave a comment