Skip to content

Commit b34ddd9

Browse files
committed
Move ObjectIdMixin to objectid.py.
1 parent ccdb2fa commit b34ddd9

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

django_mongodb/fields/auto.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from django.db.models.fields import AutoField
44
from django.utils.functional import cached_property
55

6-
from .objectid_mixin import ObjectIdMixin
6+
from .objectid import ObjectIdMixin
77

88

99
class ObjectIdAutoField(ObjectIdMixin, AutoField):

django_mongodb/fields/objectid.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,29 @@
22
from bson.errors import InvalidId
33
from django.core import exceptions
44
from django.db.models.fields import Field
5+
from django.utils.translation import gettext_lazy as _
56

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"
719

820

921
class ObjectIdField(ObjectIdMixin, Field):
1022
def get_internal_type(self):
1123
return "ObjectIdField"
1224

1325
def to_python(self, value):
26+
if value is None:
27+
return value
1428
try:
1529
return ObjectId(value)
1630
except (TypeError, InvalidId):

django_mongodb/fields/objectid_mixin.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)