Skip to content

rename MongoAutoField to ObjectIdAutoField #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/mongodb_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions django_mongodb/fields/__init__.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down
2 changes: 1 addition & 1 deletion django_mongodb/fields/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
}
Expand Down