@@ -32,21 +32,6 @@ def get_prep_value(self, value):
32
32
def rel_db_type (self , connection ):
33
33
return "objectId"
34
34
35
- def to_python (self , value ):
36
- if value is None or isinstance (value , int ):
37
- return value
38
- try :
39
- return ObjectId (value )
40
- except (errors .InvalidId , TypeError ):
41
- try :
42
- return int (value )
43
- except (ValueError , TypeError ):
44
- raise exceptions .ValidationError (
45
- self .error_messages ["invalid" ],
46
- code = "invalid" ,
47
- params = {"value" : value },
48
- ) from None
49
-
50
35
51
36
class ObjectIdField (ObjectIdMixin , Field ):
52
37
def get_internal_type (self ):
@@ -57,3 +42,15 @@ def deconstruct(self):
57
42
if path .startswith ("django_mongodb.fields.objectid" ):
58
43
path = path .replace ("django_mongodb.fields.objectid" , "django_mongodb.fields" )
59
44
return name , path , args , kwargs
45
+
46
+ def to_python (self , value ):
47
+ if value is None :
48
+ return value
49
+ try :
50
+ return ObjectId (value )
51
+ except (errors .InvalidId , TypeError ):
52
+ raise exceptions .ValidationError (
53
+ self .error_messages ["invalid" ],
54
+ code = "invalid" ,
55
+ params = {"value" : value },
56
+ ) from None
0 commit comments