#NEWLINE# @ classmethod #NEWLINE# def create_or_update_from_instance( cls , instance ) : #NEWLINE# #INDENT# '\n        Create or update an object in the database from an CommCareCase\n        ' #NEWLINE# try : #NEWLINE# #INDENT# val = cls . objects . get ( pk = cls . get_instance_id ( instance ) ) #NEWLINE# #UNINDENT# except cls . DoesNotExist : #NEWLINE# #INDENT# val = cls . from_instance ( instance ) #NEWLINE# val . save ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not val . matches_exact ( instance ) ) : #NEWLINE# #INDENT# val . update ( instance ) #NEWLINE# val . save ( ) #NEWLINE# #UNINDENT# #UNINDENT# return val