MongoDB Forms

Get the source:

An implementation of django's model forms for mongoengine documents. I am aware that there is already a similar project, but I needed support for django's modelform_factory and formset_factory. The code used in this project is mostly taken from django's modelform code.

What works

You should be able to use mongodbforms just like django's standard forms. If you can't you have most likely found a bug. Report it, please. Thank you.


mongodbforms supports forms for normal documents and embedded documents.

Normal documents

To use mongodbforms with normal documents replace djangos forms with mongodbform forms.

from mongodbforms import DocumentForm

class BlogForm(DocumentForm)

Embedded documents

For embedded documents use EmbeddedDocumentForm. The Meta-object of the form has to be provided with an embedded field name. The embedded object is appended to this. The form constructor takes an additional argument: The document the embedded document gets added to.

from mongodbforms import EmbeddedDocumentForm

class MessageForm(EmbeddedDocumentForm):
    class Meta:
        document = Message
        embedded_field_name = 'messages'

        fields = ['subject', 'sender', 'message',]

form = MessageForm(parent_document=some_document, ...)

Latest commits

Fork me on GitHub