Django Mongodb Engine: Authentication, Sessions, and the User Model

I'm new to Django and Mongodb, it seems cool, and I have a few questions! I am using Django nonrel with the Django Mongodb Engine. I hope I will not make too many mistakes :)

1) Are the Django user authentication system and Django session system working fine? Because I see on allbuttonspressed.com that there is a problem with the authentication and administration interface, and the part with a third-party written authentication protocol makes me think that the django authentication system does not work with mongodb:

You can only edit users in the admin interface by adding "djangotoolbox" to your INSTALLED_APPS. Otherwise, you will get an exception from an unsupported request that requires JOIN.

Florian Khan also wrote an authentication server that provides permission support for non-relational servers. You must use this backend if you want to use the Django permission system.

2) If the authentication system works fine, how can I add fields to the user model? I saw in Django docs that to achieve this path, the transition is to define a model with OnetoOnefield for the user model ("user = models.OneToOneField (User)") and define the other fields that we want in this model. I understand that this must be the correct path from the SQL database. But with NoSQL, like mongodb, which just seems wrong to me, if I'm not mistaken, it creates a new collection and puts in each document a user field used to link the document to the document in User (just like a foreign key). It doesn't seem to be NoSQL at all (well, it's just my feeling, but since I'm just a beginner, I might be wrong, feel free to correct me). Is there a recommended way to add fields directly to the user model?

3) When a model is used in Django, does it put all the fields in the document, even if they are empty? Isn't that a waste of space? to write many field names in documents if they are empty?

4) This question relates more to the Mongob itself than to the engine, but I will ask it anyway, you may have the answer: how much extra space does it take to index the field in the collection?

I did not think that I would write so much, I hope some of you have the courage to read me!

Thanks in advance,

Nolhian

+4
source share
1 answer

Only a partial answer, since I am not using MongoDB.

  • I am using django-nerele in a Google AppEngine project. I use these other custom applications, such as "djangotoolbox" and some servers for GAE. The admin panel and Django standard authentication work very well. I suspect this is the same for MongoDB (as indicated in the quote above)

  • You're right. The standard approach is definitely good for relational databases, but might not work or work inefficiently for NoSQL databases. A typical scenario is duplicating data in another table, so you do not need to do a JOIN. I think you can just subclass the User model and add your fields to your own model ( docs ).

+1
source

Source: https://habr.com/ru/post/1380015/


All Articles