#NEWLINE# def first_or_create( self , _attributes = None , _joining = None , _touch = True , **attributes ) : #NEWLINE# #INDENT# '\n        Get the first related model record matching the attributes or create it.\n\n        :param attributes:  The attributes\n        :type attributes: dict\n\n        :rtype: Model\n        ' #NEWLINE# if ( _attributes is not None ) : #NEWLINE# #INDENT# attributes . update ( _attributes ) #NEWLINE# #UNINDENT# instance = self . _query . where ( attributes ) . first ( ) #NEWLINE# if ( instance is None ) : #NEWLINE# #INDENT# instance = self . create ( attributes , ( _joining or { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) , _touch ) #NEWLINE# #UNINDENT# return instance