Skip to content

Instantly share code, notes, and snippets.

@sebastibe
Last active October 13, 2015 02:17
Show Gist options
  • Save sebastibe/4123412 to your computer and use it in GitHub Desktop.
Save sebastibe/4123412 to your computer and use it in GitHub Desktop.
create on the fly Django ModelForm for a given model
from django import forms
# http://stackoverflow.com/questions/3915024/dynamically-creating-classes-python
OnTheFlyForm = type("OnTheFlyForm", (forms.Form,), fields)
# ModelForm
def get_on_the_fly_form(model):
class OnTheFlyModelForm(forms.ModelForm):
class Meta:
model = model
form = OnTheFlyModelForm
return form
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment