Configuring Django’s contrib apps¶
Generally, Django’s contrib apps work out of the box, but here are some required adjustments.
Apps with models¶
Each contrib app that has models that use AutoField
(admin, auth,
contenttypes, flatpages,
redirects, and sites) must:
Be configured with an
AppConfigthat specifiesdefault_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField". See Specifying the default primary key field.Have migrations that use
ObjectIdAutoField. See Configuring migrations.
contrib.sites¶
Usually the sites framework requires the
SITE_ID setting to be an integer corresponding to the primary key of
the Site object. For MongoDB, however,
all primary keys are ObjectIds, and so
SITE_ID must be set accordingly:
from bson import ObjectId
SITE_ID = ObjectId("000000000000000000000001")
You must also use the SILENCED_SYSTEM_CHECKS setting to suppress
Django’s system check requiring SITE_ID to be an integer:
SILENCED_SYSTEM_CHECKS = [
"sites.E101", # SITE_ID must be an ObjectId for MongoDB.
]