File tree Expand file tree Collapse file tree 3 files changed +16
-16
lines changed Expand file tree Collapse file tree 3 files changed +16
-16
lines changed Original file line number Diff line number Diff line change 3
3
from django .db .models .fields import AutoField
4
4
from django .utils .functional import cached_property
5
5
6
- from .objectid_mixin import ObjectIdMixin
6
+ from .objectid import ObjectIdMixin
7
7
8
8
9
9
class ObjectIdAutoField (ObjectIdMixin , AutoField ):
Original file line number Diff line number Diff line change 2
2
from bson .errors import InvalidId
3
3
from django .core import exceptions
4
4
from django .db .models .fields import Field
5
+ from django .utils .translation import gettext_lazy as _
5
6
6
- from .objectid_mixin import ObjectIdMixin
7
+
8
+ class ObjectIdMixin :
9
+ default_error_messages = {
10
+ "invalid" : _ ("“%(value)s” value must be an Object Id." ),
11
+ }
12
+ description = _ ("Object Id" )
13
+
14
+ def db_type (self , connection ):
15
+ return "objectId"
16
+
17
+ def rel_db_type (self , connection ):
18
+ return "objectId"
7
19
8
20
9
21
class ObjectIdField (ObjectIdMixin , Field ):
10
22
def get_internal_type (self ):
11
23
return "ObjectIdField"
12
24
13
25
def to_python (self , value ):
26
+ if value is None :
27
+ return value
14
28
try :
15
29
return ObjectId (value )
16
30
except (TypeError , InvalidId ):
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments