def form_for_instance(instance, form=BaseForm, formfield_callback=(lambda f, **kwargs: f.formfield(**kwargs))):
 model = instance.__class__
 opts = model._meta
 field_list = []
 for f in (opts.fields + opts.many_to_many):
  if (not f.editable):
   continue
  current_value = f.value_from_object(instance)
  formfield = formfield_callback(f, initial=current_value)
  if formfield:
   field_list.append((f.name, formfield))
 fields = SortedDictFromList(field_list)
 return type((opts.object_name + 'InstanceForm'), (form,), {'base_fields': fields, '_model': model, 'save': make_instance_save(instance)})

def form_for_instance ( instance , form = BaseForm , formfield_callback = ( lambda f , ** kwargs : f . formfield ( ** kwargs ) ) ) : model = instance . __class__ opts = model . _meta field_list = [ ] for f in ( opts . fields + opts . many_to_many ) : if ( not f . editable ) : continue current_value = f . value_from_object ( instance ) formfield = formfield_callback ( f , initial = current_value ) if formfield : field_list . append ( ( f . name , formfield ) ) fields = SortedDictFromList ( field_list ) return type ( ( opts . object_name + 'InstanceForm' ) , ( form , ) , { 'base_fields' : fields , '_model' : model , 'save' : make_instance_save ( instance ) } )
returns a form class for the given django model instance .