@@ -52,20 +52,20 @@ def __init__(
5252 :param required: If the field is required. Whether it has to have a
5353 value or not. Defaults to False.
5454 :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
5656 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.
5858 :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.
6161 :param validation: (optional) A callable to validate the value of the
6262 field. The callable takes the value as parameter and should raise
6363 a ValidationError if validation fails
6464 :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.
6767 :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.
6969 :param **kwargs: (optional) Arbitrary indirection-free metadata for
7070 this field can be supplied as additional keyword arguments and
7171 accessed as attributes of the field. Must not conflict with any
@@ -521,14 +521,17 @@ def to_python(self, value):
521521 return value
522522
523523 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 ))
530531
531532 def prepare_query_value (self , op , value ):
533+ if value is None :
534+ return value
532535 return self .to_mongo (value )
533536
534537 def validate (self , value ):
0 commit comments