Model Serializer that supports MongoEngine, for Django Rest Framework.
# model
class Blog(Document):
owner = ReferenceField(User)
title = StringField()
extensions = ListField(EmbeddedDocument(BlogExtension))
tags = ListField(StringField())
approved = BooleanField()
# serializer
from rest_framework_mongoengine.serializers import MongoEngineModelSerializer
class BlogSerializer(MongoEngineModelSerializer):
class Meta:
model = Blog
depth = 2
exclude = ('approved', )
Notes:
- MongoEngine Model Serializer also supports DynamicDocument.
Depth
is optional and defaults to 5. It is used for ReferenceField & ListField.
pip install django-rest-framework-mongoengine
You can use this library as a package to your project:
- Step 1: Installing required files
pip install -r requirements.txt
- Step 2: make sure you're having a mongodb running locally:
/bin/mongod --dbpath [path_to_data/db/]
- Step 3: Create users and table in dbsqlite and django admin:
python manage.py syncdb
- Step 4: Run the SampleApp demo:
python manage.py runserver
Then run http://localhost:8000/ on your favorite browser to test the interface
See LICENSE