<s> from django . forms import ModelForm as DjangoModelForm <EOL> from django . core . exceptions import ObjectDoesNotExist <EOL> from django . db . models . fields import NOT_PROVIDED <EOL> class ModelForm ( DjangoModelForm ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ModelForm , self ) . __init__ ( * args , ** kwargs ) <EOL> data = { } <EOL> for k , v in self . data . items ( ) : <EOL> data [ k ] = v <EOL> self . data = data <EOL> for field in self . instance . __class__ . _meta . fields : <EOL> if field . name not in self . data . keys ( ) or self . data . get ( field . name ) == None : <EOL> inst_val = None <EOL> if self . instance . id : <EOL> try : <EOL> inst_val = getattr ( self . instance , field . name ) <EOL> inst_val = getattr ( inst_val , '<STR_LIT:id>' ) <EOL> except ( AttributeError , ObjectDoesNotExist ) : <EOL> pass <EOL> self . data [ field . name ] = inst_val <EOL> elif field . default != NOT_PROVIDED : <EOL> self . data [ field . name ] = field . default </s>
