Django Database router based on user selection - django

I'm writing a django project that will require me to route queries to
certain large databases based on the user selection.
So all the tables for django.contrib.auth and session and stuff will be
in the 'central' database, as well as a table that maps users to which
database they need to use for the main app.
Can you help me come up with a way of routing database queries this way
using a Django database router?
Log in user form has the database selection option.If the user is a valid user , then he will be connected to the his selected DB
At the start of the view could I take the logged in user from
request.user or wherever it is, and some how provide that variable to my
database router for the rest of the request?
All suggestions welcome.

Related

User login system in Django, with MongoDB as the primary database

So, here is the thing. I want the best method to log users on my website. I've already made a registration system that registers details of Users in the mongoDB using model forms.
I don't understand how to login the user in th website. Do I fetch the user data from the DB and match with the the form data entered by the user to log in, what is the best practice?

In Django Admin, can I display a listing of an unrelated record set alongside an admin form?

My use case is to implement something like a messaging form, allowing an administrator to write a message, then send it to group that they will filter from a list of users, from the User model. This is similar to the messaging to usergroups functionality in Joomla! so it's not too weird a use case.
So my admin page for the "Message" model would need to contain the Message creation form and a second recordset of site Users, which could be filtered down to those who the administrator wishes to contact.
Is this kind of thing possible in Django Admin, or do I need to dip into heavily customising an admin page?

How to structure django admin for multiple users

I'm still a complete newbie on Django, so now I'm a little bit lost on what I could do to structure my server to suit my needs.
The situation is like this: my Django admin could be accessed by the admin and multiple users. Each user can add multiple item to the server, and the server will only allow them to retrieve, modify and delete item added by them and not the other users. They will also have some custom option they can pick: like receiving notifications through emails or another channels. Meanwhile, admin can see all items, and have a filter to see all items added by one user and all users's custom option.
Any help would be appreciated.
take a look here. this is where i started with custom user models. https://wsvincent.com/django-custom-user-model-tutorial/
Django has builtin user models with basic fields like username email and password and authentication. The above link will help you create custom user models and it will be a good place to start

authentication Django on LDAP server

I would like my web application authenticate users on an ldap server (only for username and password), but that the permissions reside on django.
Not all ldap users must have access to the web application.
In particular, I would like to allow users to see only a few records (for example, suppose there is a model with a city field: some users should only be able to see records whose city field is london, others whose city is milano, etc.).
How can i define django permissions if users are defined on ldap?
How can I define the user's application admin if users are defined on ldap?
Do I need to implement a double authentication? Do I have to define ldap users who can access the web application even on django?
What is the best way to proceed?
Do you have any suggestions?
Examples?
Thanks
pacopyc
Not all LDAP users must have access to the web application.
Create a separate branch in LDAP tree for your application
What is the best way to proceed? Do you have any suggestions?
Take a look at the django-python3-ldap extension:
Define your settings in Django settings.py, then do a LDAP sync users to your local database
python manage.py ldap_sync_users

Django registering users against a list of existing usernames

I am using Django rest framework to build my application backend. I have used Django-rest-auth (https://github.com/Tivix/django-rest-auth) to enable login and registration for my app. It is already working.
However as per my new requirement, I have a list of usernames and only those usernames can register into my system. How can I achieve this?
I had few ideas (do not know if they make total sense):
1. A new model to store usernames, so that in future more usernames can be added via admin interface
2. Whenever a user makes a call from client: the entered username is checked against this new usernames table and if it exists in the table registration is allowed.
Or there can be a still easier way to do this? Any code snippets?