For instance, we want to be able to add clients. On the fly. We plan to have many - like more than 20. So we certainly don't want to have our database definition in settings, all written out like the Django tutorials. At the very least, a loop over db names.
def add_db_to_databases(DATABASES,name):if name in DATABASES:return DATABASESDATABASES[name] = {'HOST': 'localhost','PORT': '','NAME': name,'USER': '','PASSWORD': '','ENGINE': '','OPTIONS': {'autocommit': True,}}return DATABASESfor name in pro_dbs.names:DATABASES = add_db_to_databases(DATABASES,name)
What I did there is take the names from another python file, which contains a simple python list of names.
I needed to be able to add clients on the fly. This is the hard part; as of yet I have two stumbling blocks with only partial workarounds.
- I'd love to have the database names in a database themselves. Soooo much better than reading the python file with the names into a list, appending the new name to the list, than writing back to the file. But how to load from a database in the django settings file itself? It's been engineered not to allowed that.
- I'd love to be able to update settings without restarting the server. You can do certain things in that vein by messing with django.conf.settings, but it's unclear how well that'll hold up under multithreading.
All in all, not a facepalm worthy subject, but very interesting.
No comments:
Post a Comment