Reputation: 123
I would like to work with the django(currently 1.5.2) with the mongodb (currently 2.4.6). Till now I had tried:
Please advise, my goal is to run django 1.5.2 (with virtualenv) so I could use normal models with mongodb DB. What is the best approach?
Upvotes: 2
Views: 845
Reputation: 3841
You could use a SQL relational database for the django
models like User. Then you can use a Database Router to route based on the app name, if it's auth
then use the relational database. This will let you specify by app/model which database to use.
An example from someone on this site: Mixing Postgres and Mongo.
Upvotes: 1
Reputation: 82560
I'm afraid that django
and mongoengine
do not have an integration yet, but its still in the works. If you want to use mongoengine
, I would suggest that you use flask, because the other way you have to use it is rather frustrating, wherein you need to connect to mongodb
using a cursor, in your models.py
file and then inheriting from Document
to make your classes.
Thus, every single time you need to use your models, you will need to connect back, hitting your database several times over. This is not how django usually operates, since it uses one connection to handle multiple queries to make things more efficient.
This becomes a REAL pain in the long run, and I would strong discourage you using django and mongoengine
or mongodb
for that matter, and especially for a person who is brand new to django in the first place.
If you're new to django, then please use a RDBMS like Sqlite3
or PostgreSQL
to do your development. But if the use of mongodb
is a must, then I suggest that you reconsider using django in the first place, because mongodb
has a better integration with flask, through mongoengine
.
And I would suggest that you do not use anything other than mongoengine
when dealing with mongodb
, because mongoengine
has the best support for mongodb
, and is by far the most flexible option out there when working with mongodb
and python. Not only that, but the syntax is almost identical to that of django's ORM.
I deeply regret I cannot provide a better answer, the only solutions remains making a connection every single time, and not to mention that all of this does not integrate well with django's forms, which is a big bummer.
Upvotes: 3