<s> def create_or_update ( model , filter_attrs , new_attrs = { } , skip_attrs = [ ] ) : <EOL> '''<STR_LIT>''' <EOL> from django . db . utils import IntegrityError <EOL> try : <EOL> obj = model . objects . get ( ** filter_attrs ) <EOL> except model . DoesNotExist : <EOL> for k in skip_attrs : <EOL> del filter_attrs [ k ] <EOL> for k in filter_attrs . keys ( ) : <EOL> if "<STR_LIT>" in k : <EOL> del filter_attrs [ k ] <EOL> filter_attrs . update ( new_attrs ) <EOL> try : <EOL> obj = model . objects . create ( ** filter_attrs ) <EOL> except IntegrityError : <EOL> import traceback <EOL> traceback . print_exc ( ) <EOL> raise <EOL> created = True <EOL> else : <EOL> created = False <EOL> for k , v in new_attrs . items ( ) : <EOL> setattr ( obj , k , v ) <EOL> obj . save ( ) <EOL> return ( obj , created ) </s>
