Marcin Poliński Marcin Poliński - 1 year ago 84
Python Question

Managing databases in Django models, sqlite and mongoengine

I'm developing some project in Django, something to manage assets in warehouses. I want to use two databases to this. First is sqlite database, which contains any data about users. Second is mongoDB database,in which want to store all the data related to assets. The question is, how to tell to my model classes, which database they should use (models responsible for user registration etc - sqlite, models responsible for managing assets data - mongoDB)? I read about

and using
classes, but it's solutions for supported databases by Django (or maybe I don't know something), I dont know if it's good and possible to integrate it with mongoengine.

Thanks for any tip!

Answer Source

I found a solution, It's very simple. If you want your model to use mongoDB database, just create model class witch Document parameter (or EmbeddedDocument, for example class Magazine(Document):). but if you prefer default database type defined, just create class, like in django documentation (example class Person(models.Model):).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download