From a8fd899cbc1742e0ad45b5d3a5e7678cda421d07 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Tue, 7 May 2024 22:11:28 -0400 Subject: [PATCH] document how to start a Django project --- README.md | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/README.md b/README.md index 22c8c73c..2ddc47de 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,63 @@ DATABASES = { `OPTIONS` is an optional dictionary of parameters that will be passed to [`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`. + +```python +DEFAULT_AUTO_FIELD = "django_mongodb.fields.MongoAutoField" +``` + +This won't override any apps that have an `AppConfig` that specifies +`default_auto_field`. For those apps, you'll need to create a custom +`AppConfig`. + +For example, you might create `mysite/apps.py` like this: + +```python +from django.contrib.admin.apps import AdminConfig +from django.contrib.auth.apps import AuthConfig +from django.contrib.contenttypes.apps import ContentTypesConfig + + +class MongoAdminConfig(AdminConfig): + default_auto_field = "django_mongodb.fields.MongoAutoField" + + +class MongoAuthConfig(AuthConfig): + default_auto_field = "django_mongodb.fields.MongoAutoField" + + +class MongoContentTypesConfig(ContentTypesConfig): + default_auto_field = "django_mongodb.fields.MongoAutoField" +``` + +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 +you use needs to have its own migrations specific to MongoDB. + +For example, you might configure your settings like this: + +```python +MIGRATION_MODULES = { + "admin": "mongo_migrations.admin", + "auth": "mongo_migrations.auth", + "contenttypes": "mongo_migrations.contenttypes", +} +``` + +After creating a `mongo_migrations` directory, you can then run: +``` +$ python manage.py makemigrations admin auth contenttypes +Migrations for 'admin': + mongo_migrations/admin/0001_initial.py + - Create model LogEntry +... +``` + ## Known issues and limitations - The following `QuerySet` methods aren't supported: