Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Stand With Ukraine

OSS Lifecycle Gitter chat

THIS IS UNSTABLE PROJECT, IF YOU WANT TO USE IT - FIX WHAT YOU NEED

Right now we’re targeting to get things working on Django 4.2;

WARNING: This project is not in good state, and is likely to break with django updates. Do not use it for any new projects.

Recommended way for new projects is django-mongodb-backend.

Working / Django 4.2

  • [ok] sessions

  • [ok] models/fields, fields needs testing

  • [ok] views

  • [ok] auth

  • [?] admin - partially working, some things broken

Current status

Many parts of projects rewritten/removed; Instead of copying django code i try to subclass/reuse/even monkey-patch; Everything listed above is working; admin - just base fuctions like changelist/edit, not tested with every form type; need’s more work.

Some code just plaholder to make things work; django/forms/document_options.py - dirty hack absolutely required to get thigs work with django. It replaces mongo _meta on model/class and provide django-like interface. It get’s replaced after class creation via some metaclass magick.

Fields notes

  • Project uses mongoengine style argument required=False, not django style blank=False, to be compatible with mongo-types. All your fields are optional by default.

TODO

Connecting

In your settings.py file, add following lines:

MONGODB_DATABASES = {
    "default": {
        "name": database_name,
        "host": database_host,
        "password": database_password,
        "username": database_user,
        "tz_aware": True, # if you using timezones in django (USE_TZ = True)
    },
}

INSTALLED_APPS += ["django_mongoengine"]

Documents

Inhherit your documents from django_mongoengine.Document, and define fields using django_mongoengine.fields.:

from django_mongoengine import Document, EmbeddedDocument, fields

class Comment(EmbeddedDocument):
    created_at = fields.DateTimeField(
        default=datetime.datetime.now, editable=False,
    )
    author = fields.StringField(verbose_name="Name", max_length=255)
    email  = fields.EmailField(verbose_name="Email")
    body = fields.StringField(verbose_name="Comment")

class Post(Document):
    created_at = fields.DateTimeField(
        default=datetime.datetime.now, editable=False,
    )
    title = fields.StringField(max_length=255)
    slug = fields.StringField(max_length=255, primary_key=True)
    comments = fields.ListField(
        fields.EmbeddedDocumentField('Comment'), required=False,
    )

Sessions

Django allows the use of different backend stores for its sessions. MongoEngine provides a MongoDB-based session backend for Django, which allows you to use sessions in your Django application with just MongoDB. To enable the MongoEngine session backend, ensure that your settings module has 'django.contrib.sessions.middleware.SessionMiddleware' in the MIDDLEWARE_CLASSES field and 'django.contrib.sessions' in your INSTALLED_APPS. From there, all you need to do is add the following line into your settings module:

SESSION_ENGINE = 'django_mongoengine.sessions'
SESSION_SERIALIZER = 'django_mongoengine.sessions.BSONSerializer'

Django provides session cookie, which expires after `SESSION_COOKIE_AGE` seconds, but doesn’t delete cookie at sessions backend, so 'mongoengine.django.sessions' supports mongodb TTL.

How to run example app

uv sync --group dev
uv pip install -r example/tumblelog/requirements.txt
uv run python example/tumblelog/manage.py runserver

How to run tests

uv run python -m pytest

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_mongoengine-0.6.0b4.tar.gz (83.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_mongoengine-0.6.0b4-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file django_mongoengine-0.6.0b4.tar.gz.

File metadata

  • Download URL: django_mongoengine-0.6.0b4.tar.gz
  • Upload date:
  • Size: 83.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.12

File hashes

Hashes for django_mongoengine-0.6.0b4.tar.gz
Algorithm Hash digest
SHA256 3834f62215eb5906b58b7ca58a6b4db856f3cab886fcc8a4cea4a8018a9ca85f
MD5 cfb10a80cb41c5c79c81ccd982bced71
BLAKE2b-256 04491c363c8371507d66a71628691a14f5240421ca9e00458d4493e055ea8082

See more details on using hashes here.

File details

Details for the file django_mongoengine-0.6.0b4-py3-none-any.whl.

File metadata

File hashes

Hashes for django_mongoengine-0.6.0b4-py3-none-any.whl
Algorithm Hash digest
SHA256 19b45d9300827f2d8d4cb4939897b062529d5ac7b9b9cdcca0d07bbc22e12276
MD5 0a02f4eade5ee091dcb3450f38a3e083
BLAKE2b-256 a7099902583bc53a44109fd2cb52a5ec92d7cd80dd0fa10621238bd8b1f902f4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page