#NEWLINE# @ classmethod #NEWLINE# def delete_if_unreferenced( cls , model_object , publish = True , dispatch_trigger = True ) : #NEWLINE# #INDENT# delete_query = model_object . _object_key #NEWLINE# delete_query [ 'ref_count__lte' ] = 0 #NEWLINE# cls . _get_impl ( ) . delete_by_query ( ** delete_query ) #NEWLINE# confirmed_delete = False #NEWLINE# try : #NEWLINE# #INDENT# cls . get_by_id ( model_object . id ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# confirmed_delete = True #NEWLINE# #UNINDENT# if ( confirmed_delete and publish ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# cls . publish_delete ( model_object ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# LOG . exception ( 'Publish failed.' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( cls and dispatch_trigger ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# cls . dispatch_delete_trigger ( model_object ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# LOG . exception ( 'Trigger dispatch failed.' ) #NEWLINE# #UNINDENT# #UNINDENT# return model_object