I don't think Django provides a hook that will let us override or customize the behavior of QuerySet.raw() , so I think we'll have to write a custom manager that developers could use on their models that will override Queryset.raw() (or probably it's better name it something different like raw_mql() ). The link between Manager and QuerySet is here: https://github.com/django/django/blob/438fc42ac667653488200578a47e59f6608f2b0b/django/db/models/manager.py#L176-L177
So I think we need a subclass of QuerySet with a raw_mql() method and then something like:
class MongoManager(BaseManager.from_queryset(MongoQuerySet)):
pass
This could live in django_mongodb/manager.py
Then usage on the model would be:
class Model(models.Model):
objects = MongoManager()
Via @timgraham
I don't think Django provides a hook that will let us override or customize the behavior of QuerySet.raw() , so I think we'll have to write a custom manager that developers could use on their models that will override Queryset.raw() (or probably it's better name it something different like raw_mql() ). The link between Manager and QuerySet is here: https://github.com/django/django/blob/438fc42ac667653488200578a47e59f6608f2b0b/django/db/models/manager.py#L176-L177 So I think we need a subclass of QuerySet with a raw_mql() method and then something like:
This could live in django_mongodb/manager.py
Then usage on the model would be: