Django function to create form for a model object
def create_form(type, id):
"""
Create the form for the object beeing edited.
"""
inner_model = get_model('<your app>', type)
instance = inner_model.objects.get(pk=id)
class MetaForm(ModelForm):
class Meta:
model = inner_model
form = MetaForm(instance=instance)
return form
Written by Yohann Gabory
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#