MCPcopy Create free account
hub / github.com/MongoEngine/mongoengine / __init__

Method __init__

mongoengine/base/fields.py:50–138  ·  view source on GitHub ↗

:param db_field: The database field to store this field in (defaults to the name of the field) :param required: If the field is required. Whether it has to have a value or not. Defaults to False. :param default: (optional) The default value for this f

(
        self,
        db_field=None,
        required=False,
        default=None,
        unique=False,
        unique_with=None,
        primary_key=False,
        validation=None,
        choices=None,
        null=False,
        sparse=False,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

48 auto_creation_counter = -1
49
50 def __init__(
51 self,
52 db_field=None,
53 required=False,
54 default=None,
55 unique=False,
56 unique_with=None,
57 primary_key=False,
58 validation=None,
59 choices=None,
60 null=False,
61 sparse=False,
62 **kwargs,
63 ):
64 """
65 :param db_field: The database field to store this field in
66 (defaults to the name of the field)
67 :param required: If the field is required. Whether it has to have a
68 value or not. Defaults to False.
69 :param default: (optional) The default value for this field if no value
70 has been set, if the value is set to None or has been unset. It can be a
71 callable.
72 :param unique: Is the field value unique or not (Creates an index). Defaults to False.
73 :param unique_with: (optional) The other field this field should be
74 unique with (Creates an index).
75 :param primary_key: Mark this field as the primary key ((Creates an index)). Defaults to False.
76 :param validation: (optional) A callable to validate the value of the
77 field. The callable takes the value as parameter and should raise
78 a ValidationError if validation fails
79 :param choices: (optional) The valid choices
80 :param null: (optional) If the field value can be null when a default exists. If not set, the default value
81 will be used in case a field with a default value is set to None. Defaults to False.
82 :param sparse: (optional) `sparse=True` combined with `unique=True` and `required=False`
83 means that uniqueness won't be enforced for `None` values (Creates an index). Defaults to False.
84 :param **kwargs: (optional) Arbitrary indirection-free metadata for
85 this field can be supplied as additional keyword arguments and
86 accessed as attributes of the field. Must not conflict with any
87 existing attributes. Common metadata includes `verbose_name` and
88 `help_text`.
89 """
90 self.db_field = db_field if not primary_key else "_id"
91
92 self.required = required or primary_key
93 self.default = default
94 self.unique = bool(unique or unique_with)
95 self.unique_with = unique_with
96 self.primary_key = primary_key
97 self.validation = validation
98 self.choices = choices
99 self.null = null
100 self.sparse = sparse
101 self._owner_document = None
102
103 self.__auto_dereference = True
104
105 # Make sure db_field is a string (if it's explicitly defined).
106 if self.db_field is not None and not isinstance(self.db_field, str):
107 raise TypeError("db_field should be a string.")

Callers 2

__init__Method · 0.45
__init__Method · 0.45

Calls 2

joinMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected