diff --git a/.github/workflows/mongodb_settings.py b/.github/workflows/mongodb_settings.py index 280a80492..63f8f6f0c 100644 --- a/.github/workflows/mongodb_settings.py +++ b/.github/workflows/mongodb_settings.py @@ -8,7 +8,7 @@ "NAME": "djangotests-other", }, } -DEFAULT_AUTO_FIELD = "django_mongodb.fields.MongoAutoField" +DEFAULT_AUTO_FIELD = "django_mongodb.fields.ObjectIdAutoField" PASSWORD_HASHERS = ("django.contrib.auth.hashers.MD5PasswordHasher",) SECRET_KEY = "django_tests_secret_key" USE_TZ = False diff --git a/README.md b/README.md index 40a7d0bef..a66cc17a9 100644 --- a/README.md +++ b/README.md @@ -49,10 +49,10 @@ DATABASES = { [`MongoClient`](https://pymongo.readthedocs.io/en/stable/api/pymongo/mongo_client.html). In your Django settings, you must specify that all models should use -`MongoAutoField`. +`ObjectIdAutoField`. ```python -DEFAULT_AUTO_FIELD = "django_mongodb.fields.MongoAutoField" +DEFAULT_AUTO_FIELD = "django_mongodb.fields.ObjectIdAutoField" ``` This won't override any apps that have an `AppConfig` that specifies @@ -68,22 +68,22 @@ from django.contrib.contenttypes.apps import ContentTypesConfig class MongoAdminConfig(AdminConfig): - default_auto_field = "django_mongodb.fields.MongoAutoField" + default_auto_field = "django_mongodb.fields.ObjectIdAutoField" class MongoAuthConfig(AuthConfig): - default_auto_field = "django_mongodb.fields.MongoAutoField" + default_auto_field = "django_mongodb.fields.ObjectIdAutoField" class MongoContentTypesConfig(ContentTypesConfig): - default_auto_field = "django_mongodb.fields.MongoAutoField" + default_auto_field = "django_mongodb.fields.ObjectIdAutoField" ``` Then replace each app reference in the `INSTALLED_APPS` setting with the new ``AppConfig``. For example, replace `'django.contrib.admin'` with `'mysite.apps.MongoAdminConfig'`. -Because all models must use `MongoAutoField`, each third-party and contrib app +Because all models must use `ObjectIdAutoField`, each third-party and contrib app you use needs to have its own migrations specific to MongoDB. For example, you might configure your settings like this: diff --git a/django_mongodb/fields/__init__.py b/django_mongodb/fields/__init__.py index 0c5531b89..d558e0fe8 100644 --- a/django_mongodb/fields/__init__.py +++ b/django_mongodb/fields/__init__.py @@ -1,8 +1,8 @@ -from .auto import MongoAutoField +from .auto import ObjectIdAutoField from .duration import register_duration_field from .json import register_json_field -__all__ = ["register_fields", "MongoAutoField"] +__all__ = ["register_fields", "ObjectIdAutoField"] def register_fields(): diff --git a/django_mongodb/fields/auto.py b/django_mongodb/fields/auto.py index f27d60517..c79a21e8b 100644 --- a/django_mongodb/fields/auto.py +++ b/django_mongodb/fields/auto.py @@ -5,7 +5,7 @@ from django.utils.translation import gettext_lazy as _ -class MongoAutoField(AutoField): +class ObjectIdAutoField(AutoField): default_error_messages = { "invalid": _("ā€œ%(value)sā€ value must be an Object Id."), }