Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Django forms for mongodb documents

License

NotificationsYou must be signed in to change notification settings

pythonpro/django-mongodbforms

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is an implementation of django's model forms for mongoengine documents.

Requirements

Usage

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 DocumentFormclass BlogForm(DocumentForm)    ...

Embedded documents

For embedded documents useEmbeddedDocumentForm. 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.

If the form is saved the new embedded object is automatically added to the provided parent document. If the embedded field is a list field the embedded document is appended to the list, if it is a plain embedded field the current object is overwritten. Note that the parent document is not saved.

# forms.pyfrom mongodbforms import EmbeddedDocumentFormclass MessageForm(EmbeddedDocumentForm):    class Meta:    document = Message    embedded_field_name = 'messages'    fields = ['subject', 'sender', 'message',]# views.pyform = MessageForm(parent_document=some_document, ...)

Documentation

In theory the documentationDjango's modelform documentation should be all you need (except for one exception; read on). If you find a discrepancy between something that mongodbforms does and what Django's documentation says, you have most likely found a bug. Pleasereport it.

Form field generation

Because the fields on mongoengine documents have no notion of form fields every mongodbform uses a generator class to generate the form field for a db field, which is not explicitly set.

If you want to use your own generator class you can use theformfield_generator option on the form's Meta class.

# generator.pyfrom mongodbforms.fieldgenerator import MongoFormFieldGeneratorclass MyFieldGenerator(MongoFormFieldGenerator):...# forms.pyfrom mongodbforms import DocumentFormfrom generator import MyFieldGeneratorclass MessageForm(DocumentForm):    class Meta:formfield_generator = MyFieldGenerator

About

Django forms for mongodb documents

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp