Answer the question
In order to leave comments, you need to log in
What is the best way to access an external database from Django?
Hello!
I have a Python/Django project with a local sqlite3 database. During operation, the application must access and receive data from a database that has nothing to do with the project.
That is, the wonderful Django ORM cannot be used.
At the moment, I have a sql folder in the project directory, in which queries are stored in their pure form, and in the project I use a self-written module that connects the necessary driver and performs all the routine work. As a result, in the view it all comes down to
result = global_sql_driver.request('last_orders.sql')
Answer the question
In order to leave comments, you need to log in
That is, the wonderful Django ORM cannot be used.
Why? In models, you can describe table names, column names, etc. ORM itself will make requests. As a last resort, there are all sorts of query managers and other garbage like the Q class in the ORM, with which you can map the base table in the model.
You can generate a models.py file with the current database.
https://docs.djangoproject.com/en/dev/howto/legacy...
why do you need an id property in an object if you are working with an array? use index.
to update user properties, you do not need to iterate over the entire array
function UpdateUser(id, name, email) {
usersData[id].name = name;
usersData[id].email = email;
}
function UpdateUser(id, name, email) {
usersData.forEach(function (item, i, usersData) {
if (userData[i].id === id) {
usersData[i].email = email;
usersData[i].name = name;
}
});
}
Found the error myself
var usersData = [];
var userObj = {name: '', email: '',id: i = 0};
function AddUser(name, email, id) {
usersData.push({
name: name,
email: email,
id: i++
});
}
function UpdateUser(id, name , email) {
usersData.forEach(function (item, i, usersData) {
usersData[id].email = email;
usersData[id].name = name;
})
}
function DeleteUser(id) {
delete usersData[id];
}
function ShowUsers() {
console.log(usersData);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question