Publishing django views with already existing db tables - python

I have experience programming in python, but am new to Django. I recently went through the tutorial and eveything made sense, however I am wondering if I can create views from DB tables that already exists without having to create models. Or, if this isn't possible is there a way to create models to generate an ORM with a DB table that already exists?
Basically I have Aggregate metrics in data warehouse tables that I would like to publish to a web page in real time. Is Django the right tool for this? Thanks.

Use ./manage.py inspectdb to create models from an existing database.

Related

How to create a new database for each user in a database using django and mongodb?

I'm creating a web app for my school to help manage and store student documents. I'm creating the app in such a way that each student in the school gets their own database to store documents (absent notes, doctor notes, etc.). I am creating this database webapp using Django and MongoDB. I'm having a hard time figuring out how to link MongoDB and Django in such a way that I can have an infinite number of databases. Ideally, I'd like to have it so that each student gets their own database filled with their own set of documents. I was just wondering how (or if it's even possible) to create an infinite number of databases and link it to Django from MongoDB? If so, how would I set up my settings.py file and my models.py file?
As of now, I have used Pymongo as a simple way to create many databases on the original MongoDB server, but haven't found an "ORM" for MongoDB that works for Django and allows me to create many databases. If MongoDB doesn't work, could I try using something else like PostgreSQL?

django rest framework apis using legacy db without creating django default tables

I am going to develop django rest framework apis using postgres legacy database in which apart from the existing tables no other default django tables should be created. I would like to know without creating any django default tables or doing migrations,
can i able to access records from tables using ORM?
Can i able to access admin page without creating django auth table (i.e superuser)?
If no for both questions, only way to connect to db is using any db adapter like psycopg2?
can i able to access records from tables using ORM?
If the schema is same in your models and DB tables, then yes.
Can i able to access admin page without creating django auth table
(i.e superuser)?
As far as I can tell, no, you can't get that, unless your existing 'tables' already have that, and you have all the necessary credentials.
For question in #3, I'd use something less constraining like Flask if you have these problems.

create a table in django and save model to it

I am stuck on this stage where I need to save my model to a particular table. I have installed postgres and now I want to firstly create 2 tables A and B and append instance of model 'modelA' to table 'A' and of 'modelB' to B. I cannot find much on this on googling and stackoverflow in a clear form.
Try running your migrations, so that the tables will be created inside of your DB. This happens in your models.py file. Any name you give to the class of the table in the models.py, it will correspond to the same name, in lowercase and underscores, the table in your PostgreSQL DB, except if you want to override it.
Here are some nice and helpful tutorials, about Django with PostgreSQL:
Creating a Django Web Application with a PostgreSQL Database on Windows
Step-by-Step Python and Postgres Tutorial with psycopg2
Generic videos about Django database and migrations:
* Python Django Tutorial: Full-Featured Web App Part 5 - Database and Migrations
* The Basics of Django Models
I hope this helps. Please let me know if I helped you!

Making Flask connection to existing Postgres tables based on Django models

I am developing a Flask app that queries on an existing Postgres DB. This DB had been created with Django models. Do i need to reverse engineer so my models would be compatible with SQLAlchemy or will that already be. Is raw queries the way to go? I don't want to create new DBs just query and update some values in the existing ones, that had been created in Postgres using my django models.
Go check out sqlalchemy's AMAZING automap feature: http://docs.sqlalchemy.org/en/latest/orm/extensions/automap.html
Used it once in my personal project for similar purpose, it works great.

Django: If I added new tables to database, how can I query them?

Django: If I added new tables to database, how can I query them?
Do I need to create the relevant models first? Or django creates it by itself?
More specifically, I installed another django app, it created several database tables in database, and now I want to get some specific data from them? What are the correct approaches? Thank you very much!
I suppose another django app has all model files needed to access those tables, you should just try importing those packages and use this app's models.
Django doen't follow convention over configuration philosophy. you have to explicitly create the backing model for the table and in the meta tell it about the table name...

Categories