I am new in Django with MongoDB. Please suggest how to create models using MongoDB with relationship like ForeignKey, ManyToManyFields etc...
Asked
Active
Viewed 1,357 times
1 Answers
0
I suggest you use MongoEngine for Django project
please refer MongoEngine document here: http://docs.mongoengine.org/index.html
using Mongoengine you can simply create a model like this:
class YourModel(Document): # Define Model in using MongoEngine
id = IntField(unique=True) # define Integer field
percentage = FloatField(default=0.00) # define float field
user = ReferenceField('User') # foreignkey
All the fields are the same as Django as an ex: IntField, FloatField And You can use relational field (foreign key) using ReferenceField.
For more information, please follow the documentation (http://docs.mongoengine.org/index.html)

jevin kaneriya
- 135
- 10
-
Can i go for djongo. It will work with the same models & views. – Manish Kumar Apr 10 '20 at 10:47
-
You need to change your model and views according to mongoEngine and views. If you are using the Django rest framework then use **rest_framework_mongoengine* *. – jevin kaneriya Apr 10 '20 at 12:20