function creating modelform for django


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. from django.forms import ModelForm
  2.  
  3.  
  4. def create_modelform(model_, module=None):
  5. class _modelform(ModelForm):
  6. class Meta:
  7. model = model_
  8.  
  9. if module:
  10. _modelform.__module__ = module
  11. else:
  12. _modelform.__module__ = model_.__module__
  13. _modelform.__name__ = '%sForm' % model_.__name__
  14. return _modelform

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.