If it is one time selection like storing in a user level settings, you can store the database to use in user model
i.e. you have to customize default Usermodel in django and add one extra field to store the db type of the current user.
Then access the right db
Author.objects.using(request.user.database).all()
ORAuthor.objects.using('mysql').all()
Author.objects.using('postgresql').all()
You might have to use the database routers also. It depends on your detailed requirements.
Official docs -
Cheers!
On Fri, Jun 21, 2019 at 4:55 PM anilkumar sangu <sangu.anilkumar@gmail.com> wrote:
Hello,--I am working on DjangoI have a scenario likeI want to connect multiple databases. based on user selection. if user selects MySql from front end my Api could able to connect MySql. if user select postgreSql my api could able to connect to postgreSql based on user selection dynamically. how to achieve this in Django Rest ApiThanks in advance
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/50a8fe84-0966-4b2c-bcf4-725f75a78609%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMKMUjuH_j_OGDpLQfQQZ8EqChRTXXvutNb%3DK%2BJEv76QJeQmFw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment