@@ -52,20 +52,20 @@ def __init__(
52
52
:param required: If the field is required. Whether it has to have a
53
53
value or not. Defaults to False.
54
54
:param default: (optional) The default value for this field if no value
55
- has been set (or if the value has been unset). It can be a
55
+ has been set, if the value is set to None or has been unset. It can be a
56
56
callable.
57
- :param unique: Is the field value unique or not. Defaults to False.
57
+ :param unique: Is the field value unique or not (Creates an index) . Defaults to False.
58
58
:param unique_with: (optional) The other field this field should be
59
- unique with.
60
- :param primary_key: Mark this field as the primary key. Defaults to False.
59
+ unique with (Creates an index) .
60
+ :param primary_key: Mark this field as the primary key ((Creates an index)) . Defaults to False.
61
61
:param validation: (optional) A callable to validate the value of the
62
62
field. The callable takes the value as parameter and should raise
63
63
a ValidationError if validation fails
64
64
:param choices: (optional) The valid choices
65
- :param null: (optional) If the field value can be null. If no and there is a default value
66
- then the default value is set
65
+ :param null: (optional) If the field value can be null when a default exist. If not set, the default value
66
+ will be used in case a field with a default value is set to None. Defaults to False.
67
67
:param sparse: (optional) `sparse=True` combined with `unique=True` and `required=False`
68
- means that uniqueness won't be enforced for `None` values
68
+ means that uniqueness won't be enforced for `None` values (Creates an index). Defaults to False.
69
69
:param **kwargs: (optional) Arbitrary indirection-free metadata for
70
70
this field can be supplied as additional keyword arguments and
71
71
accessed as attributes of the field. Must not conflict with any
@@ -521,14 +521,17 @@ def to_python(self, value):
521
521
return value
522
522
523
523
def to_mongo (self , value ):
524
- if not isinstance (value , ObjectId ):
525
- try :
526
- return ObjectId (str (value ))
527
- except Exception as e :
528
- self .error (str (e ))
529
- return value
524
+ if isinstance (value , ObjectId ):
525
+ return value
526
+
527
+ try :
528
+ return ObjectId (str (value ))
529
+ except Exception as e :
530
+ self .error (str (e ))
530
531
531
532
def prepare_query_value (self , op , value ):
533
+ if value is None :
534
+ return value
532
535
return self .to_mongo (value )
533
536
534
537
def validate (self , value ):
0 commit comments