==================
Django-MongoEngine
==================
|lifecycle| |gitter|
.. |lifecycle| image:: https://img.shields.io/osslifecycle/MongoEngine/django-mongoengine
:alt: OSS Lifecycle
.. |gitter| image:: https://badges.gitter.im/gitterHQ/gitter.png
:target: https://gitter.im/MongoEngine/django-mongoengine
:alt: 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.
It's better to use raw mongoengine.
Working / Django 3.2-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
------------
* mongo defaults Field(required=False), changed to django-style defaults
-> Field(blank=False), and setting required = not blank in Field.__init__
TODO
----
* Sync some files/docs that removed from mongoengine: https://github.com/seglberg/mongoengine/commit/a34f4c1beb93f430c37da20c8fd96ce02a0f20c1?diff=unified
* Add docs for integrating: https://github.com/hmarr/django-debug-toolbar-mongo
* Take a look at django-mongotools: https://github.com/wpjunior/django-mongotools
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'), blank=True,
)
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 <http://docs.mongodb.org/manual/tutorial/expire-data/>`_.
.. note:: ``SESSION_SERIALIZER`` is only necessary in Django>1.6 as the default
serializer is based around JSON and doesn't know how to convert
``bson.objectid.ObjectId`` instances to strings.
How to run example app
----------------------
.. code::
poetry install
poetry run pip install -r example/tumblelog/requirements.txt
poetry run python example/tumblelog/manage.py runserver
How to run tests
----------------
.. code::
poetry install
poetry run python -m pytest
Raw data
{
"_id": null,
"home_page": "https://github.com/mongoengine/django-mongoengine",
"name": "django-mongoengine",
"maintainer": "",
"docs_url": "https://pythonhosted.org/django-mongoengine/",
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Ross Lawley",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/9c/34/8f58c81b0676e57cb6cb2e83298f84a89b06d123d31712d85baec5aad91d/django-mongoengine-0.5.6.tar.gz",
"platform": null,
"description": "==================\nDjango-MongoEngine\n==================\n\n|lifecycle| |gitter|\n\n.. |lifecycle| image:: https://img.shields.io/osslifecycle/MongoEngine/django-mongoengine\n :alt: OSS Lifecycle\n\n.. |gitter| image:: https://badges.gitter.im/gitterHQ/gitter.png\n :target: https://gitter.im/MongoEngine/django-mongoengine\n :alt: Gitter chat\n\n\nTHIS IS UNSTABLE PROJECT, IF YOU WANT TO USE IT - FIX WHAT YOU NEED\n\nRight now we're targeting to get things working on Django 4.2;\n\nWARNING: This project is not in good state, and is likely to break with django updates.\nIt's better to use raw mongoengine.\n\nWorking / Django 3.2-4.2\n------------------------\n\n* [ok] sessions\n* [ok] models/fields, fields needs testing\n* [ok] views\n* [ok] auth\n* [?] admin - partially working, some things broken\n\nCurrent status\n-------------------------------------------------------------------------------\n\nMany parts of projects rewritten/removed;\nInstead of copying django code i try to subclass/reuse/even monkey-patch;\nEverything listed above is working; admin - just base fuctions\nlike changelist/edit, not tested with every form type; need's more work.\n\nSome code just plaholder to make things work;\n`django/forms/document_options.py` - dirty hack absolutely required to\nget thigs work with django. It replaces mongo _meta on model/class and\nprovide django-like interface.\nIt get's replaced after class creation via some metaclass magick.\n\nFields notes\n------------\n\n* mongo defaults Field(required=False), changed to django-style defaults\n -> Field(blank=False), and setting required = not blank in Field.__init__\n\n\n\nTODO\n----\n\n* Sync some files/docs that removed from mongoengine: https://github.com/seglberg/mongoengine/commit/a34f4c1beb93f430c37da20c8fd96ce02a0f20c1?diff=unified\n* Add docs for integrating: https://github.com/hmarr/django-debug-toolbar-mongo\n* Take a look at django-mongotools: https://github.com/wpjunior/django-mongotools\n\nConnecting\n==========\n\nIn your **settings.py** file, add following lines::\n\n MONGODB_DATABASES = {\n \"default\": {\n \"name\": database_name,\n \"host\": database_host,\n \"password\": database_password,\n \"username\": database_user,\n \"tz_aware\": True, # if you using timezones in django (USE_TZ = True)\n },\n }\n\n INSTALLED_APPS += [\"django_mongoengine\"]\n\nDocuments\n=========\nInhherit your documents from ``django_mongoengine.Document``,\nand define fields using ``django_mongoengine.fields``.::\n\n from django_mongoengine import Document, EmbeddedDocument, fields\n\n class Comment(EmbeddedDocument):\n created_at = fields.DateTimeField(\n default=datetime.datetime.now, editable=False,\n )\n author = fields.StringField(verbose_name=\"Name\", max_length=255)\n email = fields.EmailField(verbose_name=\"Email\")\n body = fields.StringField(verbose_name=\"Comment\")\n\n class Post(Document):\n created_at = fields.DateTimeField(\n default=datetime.datetime.now, editable=False,\n )\n title = fields.StringField(max_length=255)\n slug = fields.StringField(max_length=255, primary_key=True)\n comments = fields.ListField(\n fields.EmbeddedDocumentField('Comment'), blank=True,\n )\n\n\nSessions\n========\nDjango allows the use of different backend stores for its sessions. MongoEngine\nprovides a MongoDB-based session backend for Django, which allows you to use\nsessions in your Django application with just MongoDB. To enable the MongoEngine\nsession backend, ensure that your settings module has\n``'django.contrib.sessions.middleware.SessionMiddleware'`` in the\n``MIDDLEWARE_CLASSES`` field and ``'django.contrib.sessions'`` in your\n``INSTALLED_APPS``. From there, all you need to do is add the following line\ninto your settings module::\n\n SESSION_ENGINE = 'django_mongoengine.sessions'\n SESSION_SERIALIZER = 'django_mongoengine.sessions.BSONSerializer'\n\nDjango provides session cookie, which expires after\n```SESSION_COOKIE_AGE``` seconds, but doesn't delete cookie at sessions\nbackend, so ``'mongoengine.django.sessions'`` supports `mongodb TTL <http://docs.mongodb.org/manual/tutorial/expire-data/>`_.\n\n.. note:: ``SESSION_SERIALIZER`` is only necessary in Django>1.6 as the default\n serializer is based around JSON and doesn't know how to convert\n ``bson.objectid.ObjectId`` instances to strings.\n\n\nHow to run example app\n----------------------\n.. code::\n\n poetry install\n poetry run pip install -r example/tumblelog/requirements.txt\n poetry run python example/tumblelog/manage.py runserver\n\n\nHow to run tests\n----------------\n.. code::\n\n poetry install\n poetry run python -m pytest\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "Django support for MongoDB via MongoEngine",
"version": "0.5.6",
"project_urls": {
"Download": "https://github.com/mongoengine/django-mongoengine/tarball/master",
"Homepage": "https://github.com/mongoengine/django-mongoengine"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9c348f58c81b0676e57cb6cb2e83298f84a89b06d123d31712d85baec5aad91d",
"md5": "408c462402516e34a58a8d8bab684dae",
"sha256": "0474b32f818b442e3646ae1853a703fb1be9170dbf394ee7dfdd97e3a7d7b726"
},
"downloads": -1,
"filename": "django-mongoengine-0.5.6.tar.gz",
"has_sig": false,
"md5_digest": "408c462402516e34a58a8d8bab684dae",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 177571,
"upload_time": "2023-11-03T08:55:24",
"upload_time_iso_8601": "2023-11-03T08:55:24.558907Z",
"url": "https://files.pythonhosted.org/packages/9c/34/8f58c81b0676e57cb6cb2e83298f84a89b06d123d31712d85baec5aad91d/django-mongoengine-0.5.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-03 08:55:24",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mongoengine",
"github_project": "django-mongoengine",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "django-mongoengine"
}