def model_form(model, db_session=None, base_class=Form, only=None, exclude=None, field_args=None, converter=None, exclude_pk=True, exclude_fk=True, type_name=None):
 class ModelForm(base_class, ):
  u'Sets object as form attribute.'
  def __init__(self, *args, **kwargs):
   if (u'obj' in kwargs):
    self._obj = kwargs[u'obj']
   super(ModelForm, self).__init__(*args, **kwargs)
 if (not exclude):
  exclude = []
 model_mapper = model.__mapper__
 for prop in model_mapper.iterate_properties:
  if ((not hasattr(prop, u'direction')) and prop.columns[0].primary_key):
   if exclude_pk:
    exclude.append(prop.key)
  if (hasattr(prop, u'direction') and exclude_fk and (prop.direction.name != u'MANYTOMANY')):
   for pair in prop.local_remote_pairs:
    exclude.append(pair[0].key)
 type_name = (type_name or str((model.__name__ + u'Form')))
 field_dict = model_fields(model, db_session, only, exclude, field_args, converter)
 return type(type_name, (ModelForm,), field_dict)

def model_form ( model , db_session = None , base_class = Form , only = None , exclude = None , field_args = None , converter = None , exclude_pk = True , exclude_fk = True , type_name = None ) : class ModelForm ( base_class , ) : def __init__ ( self , * args , ** kwargs ) : if ( u'obj' in kwargs ) : self . _obj = kwargs [ u'obj' ] super ( ModelForm , self ) . __init__ ( * args , ** kwargs ) if ( not exclude ) : exclude = [ ] model_mapper = model . __mapper__ for prop in model_mapper . iterate_properties : if ( ( not hasattr ( prop , u'direction' ) ) and prop . columns [ 0 ] . primary_key ) : if exclude_pk : exclude . append ( prop . key ) if ( hasattr ( prop , u'direction' ) and exclude_fk and ( prop . direction . name != u'MANYTOMANY' ) ) : for pair in prop . local_remote_pairs : exclude . append ( pair [ 0 ] . key ) type_name = ( type_name or str ( ( model . __name__ + u'Form' ) ) ) field_dict = model_fields ( model , db_session , only , exclude , field_args , converter ) return type ( type_name , ( ModelForm , ) , field_dict )
create a wtforms form for a given django model class:: from wtforms .