django: How to save a Model instance to another project's database?
Suppose that a user creates an instance of MyModel 开发者_C百科in ProjectA that uses sqlite3 database site1.db. How would I in turn save this instance in site2.db owned by ProjectB?
You could set up two databases using Django 1.2s multi-db support (eg "db_one" and "db_two") and specify which database you want to save that instance to: myfoo.save(using='db_one')
However, if you're loading from one and potentially saving to another, you could run into a world of data integrity hurt. You should also look at master-slave replication as another solution, or just avoid having to save to a separate database unless you really really have to. The fact that you're dealing with SQLite here implies you're just playing around, rather than dealing with live apps, so if you can avoid this through better design, that's definitely the best way forward
精彩评论