Multiple Databases in 1 Django Project - python

I am planning to develop a AI-Enabled Stock Market Project using Django & Tensorflow
For Clients, I plan to use MSSQL
For Stock Tickers, I plan to use MongoDB
How do I do it in Django?
I am in Planning stage

Django is good for using a single database. I strongly advise you to use an API. This allows you to connect to as many databases as you want. You can use Django Rest API if you want.
However you can find this documentation : docs.djangoproject.com/en/4.1/topics/db/multi-db

Related

Verifying in external Django REST API if a Wordpress user is a paid subscriber or not

I have been working on a program in python that I want to make available to paid subscribers via REST. I'm currently thinking of having the frontend made in Wordpress and then host the backend somewhere else.
In wordpress there are a bunch of plugins to handle paid subscribers and so on and everything seems great but my concern is how do I verify this on the backend that is hosted somewhere else?
If I use Django, is there any way I can make some kind of call to the Wordpress server(?) and verify that the user that is trying to fetch items are an paid subscriber?
I made a Diagram to kind of show what I mean. Basically B should only answer back with items if the caller A is a paid subscriber.
I've read that it is possible to generate an API key that will be needed in order to fetch data from the API, I've also read ways of hiding this call from the frontend to the backend from the user by using some kind of relay on wordpress. Might be wrong here.
Is there any preferred way of doing this?
Is Django REST & Wordpress suitable options to do this?
You can do that using the Django REST framework(DRF) which is used for such purpose for making the rest API's.
As per your query i would suggest you to the DRF to read the data from wordpress database and perform the validation on top of it.
Here are some links that you can use for reference :-
https://pythonrepo.com/repo/istrategylabs-django-wordpress-python-third-party-apis-wrappers
https://www.ianlewis.org/en/administer-wordpress-django-admin
In programming almost anything is possible. However, since wordpress is built in php I would not say that it would be possible to work directly with it. But, (MAYBE) you can connect the wordpress database to django for READ only and create an api.
How I would do it if I had this task:
Connect Django to an existing db (your wordpress db):
Django itself teaches you how to connect with a legacy database from its documentation.
Django comes with a utility called inspectdb that can create models by
introspecting an existing database. You can view the output by running
this command:
$ python manage.py inspectdb
Save this as a file by using standard Unix output redirection:
$ python manage.py inspectdb > models.py
**This feature is meant as a shortcut, not as definitive model generation.**
Since you created the models you can create your endpoints:
Create you serializers and viewsets from the models that was auto-generated by django from your wordpress db.
Display the data you need such as the user data you need to fetch ex:paid_subscriber = True or paid_subscriber = 1. Certainly it will be there.
I think the only issue you will have is to connect with the wordpress database. After you have done this in django nothing can stop you to create endpoints with django-rest-framework displaying the data it has.

What will be the best approach for setting up multiple subdomains in a single django project using mysql?

I am about to build a web-app and use it as a product for multiple organizations.
Let's say my domain name is example.com
And I have 2 customers, org1 (Organization 1) and org2 (Organization 2)
So, my sub domains would be org1.example.com and org2.example.com
Now, I have gone through the Django tenant approach which uses PostgreSQL. But I am looking for something in MySQL.
But my question is that is it possible for me to use MySQL and use separate databases, to maintain risk free and also data privacy for orgs, and also use Django tenant or is there some different approach to solve this subdomain issue?
Do note, I'll be using my platform as a product so the subdomains would be given to each client who would be given credentials to access the platform (Kinda like an inventory system).
Any links or videos is highly appreciated.
I think there are 2 ways (according to me) of doing it.
You can use proxy API to make the process easy. You have to keep and maintain only one DB. Just use different URLs for different subdomains.
This is my personal method which I am currently using. I use Pythonanywhere for deploying my applications. This is the most convenient platform I have ever seen for the web.
Just map your domains/subdomains to the same project directory and you can use the same Mysql database for all websites without any issue.

Elasticsearch with Django and Mongoengine

I have a django REST application that uses Mongoengine. I want to integrate the application with elasticsearch. I understand that databases (like MySQL, Postgres etc.) can be integrated with elasticsearch using haystack but how to do it with MongoDB?
Saim, the fact you want to add elasticsearch to the stack means that you might want to index the data that is managed by mongoengine for full-text search and aggregation purposes. So you are looking for a library to index models (stored in mongo) and be accessible through the django API, I'd recommend this article ElasticSearch with Django the easy way where the author integrates the Django models to write into ES index via elasticsearch-py and read[search] directly using elasticsearch DSL via elasticsearch-dsl, you will realize this approach is database agnostic as well.
IMO, I have done some integrations Django<--->ES, the simpler ones, use directly the elasticsearch http api inside a Django model manager to nail the task.

Use Django with MongoDB

I have a large mongo database with documents and i want to make Django website that is going to be a client to this mongo database but it can only filter (aggregate) and view information from database without any edit/update operations. I don't want to put other web site data (users' data, comments, other information) to mongo db.
I'm new to django framework and i wonder if it is better to connect mongodb and django using, for example, mongoengine and use two databases (one for the web site data, and the second one for external documents in mongodb) or use pymongo inside django to fetch data from external db and somehow transform it to djungo models?
Yup, you're spot on, in your case of needing two separate databases, it would be better to use mongoengine in order to use two separate databases. Check out this link. It goes over defining what database to use on a per-model basis so to say.
That most likely would work great. Basically you can query using the model the same way, regardless of the database is uses, but describe which database to use on the model itself.
Hope this helps!

Any python web framework with the following features?

As the basic framework core:
Request Lifecycle REST
Routing
Requests & Input
Views & Responses
Controllers
Errors & Logging
And these features would make our dev easy and fast:
Authentication
Cache
Core Extension
Events
Facades
Forms & HTML
IoC Container
Mail
Pagination
Queues
Security
Session
SSH
Templates
Unit Testing
Validation
And really good support for MongoDB.
Is there any such framework?
There is a fork of Django that supports non relational databases. For my own projects I prefer to use a hybrid: standard (relational) Django, with MongoEngine for entities I want to store in MongoDB. The syntax is almost identical to django.db models.
I'm kinda confused by the desire of a "REST lifecycle" combined with features like "Session", "Input", etc.
For a general purpose Web/API application you might want to check out on Flask and Flask-PyMongo. Could be a good match for your use case.
If you're looking into building a RESTful Web Service, then the Eve REST API framework (which is powered by Flask and supports MongoDB out of the box) could be a good choice. You can then peek into the source of extensions like Eve-Docs to learn how to, eventually, integrate the webservice with HTML/static/dynamic pages (Flask style.)
Try Django.. im not sure but worth trying

Categories

Resources