(model, registry, only_fields, exclude_fields, non_required_fields)
return fields, self_referenced
Args:
        model (mongoengine.Document):
        registry (.registry.Registry):
        only_fields ([str]):
        exclude_fields ([str]):

    Returns:
        (OrderedDict, OrderedDict): converted fields and self reference fields.
Args:
        model (mongoengine.Document):
        registry (.registry.Registry):
        only_fields ([str]):
        exclude_fields ([str]):
Args : model ( mongoengine . Document ) : registry ( . registry . Registry ) : only_fields ( [ str ] ) : exclude_fields ( [ str ] ) :
def construct_fields(model, registry, only_fields, exclude_fields, non_required_fields):
    """
    Args:
        model (mongoengine.Document):
        registry (.registry.Registry):
        only_fields ([str]):
        exclude_fields ([str]):

    Returns:
        (OrderedDict, OrderedDict): converted fields and self reference fields.

    """
    _model_fields = get_model_fields(model)
    fields = OrderedDict()
    self_referenced = OrderedDict()
    for name, field in _model_fields.items():
        is_not_in_only = only_fields and name not in only_fields
        is_excluded = name in exclude_fields
        if is_not_in_only or is_excluded:
            # We skip this field if we specify required_fields and is not
            # in there. Or when we exclude this field in exclude_fields
            continue
        if isinstance(field, mongoengine.ListField):
            if not field.field:
                continue
            # Take care of list of self-reference.
            document_type_obj = field.field.__dict__.get("document_type_obj", None)
            if (
                document_type_obj == model._class_name
                or isinstance(document_type_obj, model)
                or document_type_obj == model
            ):
                self_referenced[name] = field
                continue
        converted = convert_mongoengine_field(field, registry)
        if not converted:
            continue
        else:
            if name in non_required_fields and 'required' in converted.kwargs:
                converted.kwargs['required'] = False
        fields[name] = converted

    return fields, self_referenced
def construct_fields ( model , registry , only_fields , exclude_fields , non_required_fields ) : _model_fields = get_model_fields ( model ) fields = OrderedDict ( ) self_referenced = OrderedDict ( ) for name , field in _model_fields . items ( ) : is_not_in_only = only_fields and name not in only_fields is_excluded = name in exclude_fields if is_not_in_only or is_excluded : # We skip this field if we specify required_fields and is not # in there. Or when we exclude this field in exclude_fields continue if isinstance ( field , mongoengine . ListField ) : if not field . field : continue # Take care of list of self-reference. document_type_obj = field . field . __dict__ . get ( "document_type_obj" , None ) if ( document_type_obj == model . _class_name or isinstance ( document_type_obj , model ) or document_type_obj == model ) : self_referenced [ name ] = field continue converted = convert_mongoengine_field ( field , registry ) if not converted : continue else : if name in non_required_fields and 'required' in converted . kwargs : converted . kwargs [ 'required' ] = False fields [ name ] = converted return fields , self_referenced