How can I login users while using Djongo?

In the documentation for Djongo it is specified to import models from the djongo package to create a model.

However if I want to use the authentication system provided by Django by extending the User model can I do this?

At a minimum you could write a custom authentication backend that uses your djongo model as the User object. (Possibly storing the traditional User object as an embedded object.)

(By “at a minimum”, I mean that there may be other ways of doing this that are easier - but this should be able to work.)


Hi Ken,

Writing a custom authentication backend seems like a complex thing to do for someone who just started using Django. I am trying to use the authentication system already provided by defining a new custom user class that extends the AbstractUser one. However, I am not sure if this is compatible with Djongo or if it will result in conflicts.

Ok, but you’re opening a real can of worms here.

By the way you’re phrasing this question, I’m getting the impression that you’re trying to use Djongo to have Django use MongoDB instead of PostgreSQL (or some other relational DB), instead of using it in addition to your PostgreSQL DB.

If that’s the case, then I think you’re facing many more problems than just the User table, because all of the Django built-in infrastructure regarding groups, permissions, content types, etc are all built on standard relational tables, and would all need to be altered for this to work.


You are right. I am using MongoDB instead of PostgreSQL and the reason I am using Djongo is that it allows me to use the ORM model provided by Django. Would you recommend using PostgreSQL for my user database and MongoDB for the rest of my web application?

Yes, I recommend using PostgreSQL for everything that doesn’t absolutely need to be in MongoDB - and, in fact, given the quality of the PostgreSQL JSON support, I rarely recommend the use of MongoDB at all when using Django. About the only time I do is when I have another application populating a MongoDB, and I need to query/display data from it in my Django app.

Thank you for your recommendation. I am just a junior software developer in the team, but I will make sure to pass this to my manager.