#NEWLINE# def get_field_info( model ) : #NEWLINE# #INDENT# '\n    Given a model class, returns a `FieldInfo` instance, which is a\n    `namedtuple`, containing metadata about the various field types on the model\n    including information about their relationships.\n    ' #NEWLINE# if issubclass ( model , mongoengine . EmbeddedDocument ) : #NEWLINE# #INDENT# pk = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pk = model . _fields [ model . _meta [ 'id_field' ] ] #NEWLINE# #UNINDENT# fields = OrderedDict ( ) #NEWLINE# references = OrderedDict ( ) #NEWLINE# embedded = OrderedDict ( ) #NEWLINE# def add_field( name , field ) : #NEWLINE# #INDENT# if isinstance ( field , REFERENCING_FIELD_TYPES ) : #NEWLINE# #INDENT# references [ name ] = get_relation_info ( field ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( field , EMBEDDING_FIELD_TYPES ) : #NEWLINE# #INDENT# embedded [ name ] = get_relation_info ( field ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( field , COMPOUND_FIELD_TYPES ) : #NEWLINE# #INDENT# fields [ name ] = field #NEWLINE# if field . field : #NEWLINE# #INDENT# add_field ( ( name + '.child' ) , field . field ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( field is pk ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# fields [ name ] = field #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# for field_name in model . _fields_ordered : #NEWLINE# #INDENT# add_field ( field_name , model . _fields [ field_name ] ) #NEWLINE# #UNINDENT# fields_and_pk = OrderedDict ( ) #NEWLINE# fields_and_pk [ 'pk' ] = pk #NEWLINE# fields_and_pk [ getattr ( pk , 'name' , 'pk' ) ] = pk #NEWLINE# fields_and_pk . update ( fields ) #NEWLINE# return FieldInfo ( pk , fields , references , fields_and_pk , embedded )