#NEWLINE# def primary_key( cls ) : #NEWLINE# #INDENT# '\n    Utility function to get the primary key\n    of the class. In case of multiple primary keys,\n    use the <classname>_id convention\n    ' #NEWLINE# keys = class_keys ( cls ) #NEWLINE# if ( len ( keys ) > 1 ) : #NEWLINE# #INDENT# pk = ( cls . __name__ . lower ( ) + '_id' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pk = next ( iter ( keys ) , None ) #NEWLINE# #UNINDENT# if ( pk not in cls . __dict__ ) : #NEWLINE# #INDENT# if ( 'pk_field' in cls . __dict__ ) : #NEWLINE# #INDENT# pk = cls . __dict__ [ 'pk_field' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise KeyNotFoundException ( ( 'Could not figure out primary key fieldfor %s model. Tried to first use %s as field name,and then looked for pk_field attr which was also missing' % ( cls . __name__ , pk ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# return pk