Answer the question
In order to leave comments, you need to log in
How to dynamically create tables in django?
I'm new and trying to write a trial assignment. I figured it out myself, I do it myself.
The question is, I can not understand how to write a model.
I have a database, this database has indicators such as cpu, network, commit, system_io.
What I want:
1. A model for a table that stores the database and connection parameters (name, host, user, password)
2. A model that stores the value of the indicators of this database.
The problem itself is that if I have more than one base, then I want a separate plate for each. And there already store the cpu and stuff.
Is this approach correct? If yes, how is it implemented? I don't ask you to write the code for me. I want to understand how it should work. Well if someone came across examples - I will be glad to look. Thanks in advance.
Answer the question
In order to leave comments, you need to log in
I do not really understand what you want, but if you believe what is written, this is horror
1) The database does not and cannot have "indicators" cpu, network, etc. There may be table fields.
2) Store the name-host-password in the database (and even several databases)? You need something super-secure to do that.
3) Why do you need several bases?
4) Tables to create dynamically incorrectly.
Most likely you will have to work through cursors, and climb into databases with your bare hands ... or even climb into databases through ssh tunnels ... But most likely something is wrong with the architecture of what you have in mind. Django is not provided for this. There, even climbing through cursors into the database makes sense only in extreme cases, when everything that can be done to improve performance has already been done.
I think you need to rethink the architecture as a whole.
For the 1st project 1 database. Access to connect to it in the project configs.
The database contains tables.
For example, if you are trying to make a database for each of your users, then create a "user" table and a data table, tables related by user ID. So each of your users will have their own data.
Likewise, for anything.
Relationship between them by object ID. Thus, you will have only 2 tables, and you can easily get all the data, knowing who it belongs to.
As they said earlier, and I fully agree, it is wrong to create dynamic tables, and even more so a database.
If it seems to you that this is necessary, then by 99% you need to revise the architecture of the project.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question