I am using Postgresql in Django and Python,and I do all the CRUD operation successfully but I don't know how can I call Postgresql procedure from Django and show the result in my web application!!
This should be completed using Django's ORM (Object Relational Mapper) querysets which is a Django wrapper that adds a layer of abstraction above an SQL query that retreives a given dataset from PostgreSQL (or another supported database).
Indeed, the existence of this layer is in place for security reasons in addition to enabling a developer to use any of the supported underlying databases (SQLite3, PostgreSQl, MySQL, Oracle or Maria DB (Django 3.0+)) by simply switching out the database credentials and settings.
The rendering of the datasets will be completed with either Django's templating system if you're usind Django across the entire stack. It could also be completed by creating APIs and using a front-end framework to render from them.
You should Google Django ORM and Datasets for further information, documentation and tutorials to achieve this.
Related
We have an existing Apache Ignite in-memory DB with lots of stored data. I want to connect my existing Django web application to the Ignite DB in order to query the existing data. Are there any examples of how to connect a Django application to an Apache Ignite DB and how to query the DB using the Django ORM?
You can use JDBC drivers with Django ORM: How to write custom database adapter for django using JDBC drivers?
Then, you can use Ignite JDBC driver: https://ignite.apache.org/docs/latest/SQL/JDBC/jdbc-driver
Django ORM requires a special adapter for each kind of database server. Such an adapter is called “database backend” in Django terminology. There is no Django database backend for Ignite. There is also no universal, middle-ground backend I know of, that can be used with Ignite.
You can implement your own custom backend (guidelines) or try to pick up the latest attempt in creating a more-or-less server-independent ODBC backend. But in your place I'd probably not get involved in any of this, since it implies a lot of work not directly related to your task.
I'd just convert the data with one-off script (or Django management command), using pyodbc or pyignite as a source and Django model as a target.
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.
I already have my flask-admin app with its models and database and tables created..
Now I would like to add a field to model and that should be reflected in the database by a new column in the model's corresponding table.
With django one would create then apply migrations..
How do I make migrations/schema-changes in flask-admin?
I would recommend checking out the section on SQLAlchemy-based database migrations in Miguel Grinberg's Database Flask Mega-Tutorial. He uses low-level SQLAlchemy APIs to put the database under version control and automate the process of database version upgrades or downgrades.
Alternatively, I recommend using Miguel Grinberg's Flask-Migrate extension which implements the functionality he describes in the aforementioned tutorial. Using this extension, you simply add an instance of the Migrate object to your application, then perform database migrations using a command line interface provided by the extension.
So I'm starting a new Django project that essentially requires the login & registration process be routed through an EXTERNAL & ALREADY created database.
Is it possible to have the User model use an EXTERNAL database table ONLY when Django is:
Logging in a user, to check if the login is valid
Registering a user, inserting data for that user in the external database
I would like for the rest of the Django server to use a local database.
If so, could someone either provide examples or guide me to documentation on the subject?
Easiest way to use multiple database with Django is to use a database routing. By default Django stick to single database, however, if you want to implement more interesting database routing system, you can define and install your own database routers.
Database routers are installed using the DATABASE_ROUTERS setting. You have to specify this setting in your settings.py file
What you have to do is write one AuthRouter as described Django documentation Django Multiple Database
"Yes, but"
What you are looking for in the docs is called "database router".
There is even an example for the auth app in the docs there.
But, there is s serious drawback to consider with this approach:
We cannot have cross-database relationships in the models. If auth tables are in a separate database, this means that any otehr app that needs a foreign key to User model is going to run into problems. You might be able to "fake" the relationships using a db that doesn't enforce relationship checks (SQLite or MyISAM/MySQL).
Out of the box, such apps are: session, authtoken, and admin (and probably more).
Alternatively, a single-sign-on solution might do a better job: django-sso, or django-mama-cas + django-cas-ng, or the commercial Stormpath.
We have our own custom NoSQL storage system (sort of a document database), and we want a Django app above it.
I want to write a backend that will allow me to connect to our database. I don't care about the Django ORM because we have our own library for querying our database.
What would be the simplest & quickest way of doing this? Rewriting
& overriding the django.db.backends.base classes seems too much of
a hassle since we don't care about Django's ORM. What we basically
need is a way to keep a connection alive, and have the queries run
against the database from our views.py file
If we want to keep the Django auth system, should we rewrite that part so that Django creates the User model etc. in our DB? Perhaps we should have two databases, a simple RDBMS for the authentication part, and the rest of the data in our custom database?
Thanks in advance!