def document_to_dict(instance, fields=None, exclude=None):
    """
    Returns a dict containing the data in ``instance`` suitable for passing as
    a Form's ``initial`` keyword argument.

    ``fields`` is an optional list of field names. If provided, only the named
    fields will be included in the returned dict.

    ``exclude`` is an optional list of field names. If provided, the named
    fields will be excluded from the returned dict, even if they are listed in
    the ``fields`` argument.
    """
    # avoid a circular import
    structure = instance.structure

    data = {}
    for field_name in structure.keys():
        if fields and not field_name in fields:
            continue
        if exclude and field_name not in exclude:
            continue
        data[field_name] = value_from_document(instance, field_name)

    return data
dataset/ETHPy150Open peterbe/django-mongokit/django_mongokit/forms/forms.py/document_to_dict/operator `in` -> `not in`