How to share a Django model?
First is it dumb to use DJango as a quick/dirty data access method? We have a backend process that will be feeding a GUI which will be implemented with django, and we figured we could just share a model between them. We dont care about performance the backend process just needs a quick way to throw something in a DB.
Assuming is not dumb how to we go about sharing a model between a UI and Backend process?
Right now we have the "model" defined we just dont know where it should reside. We tried putting it in the backend process in a model package, but since its an app we can't really generate the SQL for it.
We also tried just creating a models.py and importing our models but it doesn't generate any sql.
Behind the scenes I know it uses[app_name]_[table/model] for the db table name, so are we trying 开发者_如何学编程to do something we shouldn't?
Really would like to know the correct way to use a shared django model. Any help would be appreciated.
I currently have defined the model outside of the ui, and I am trying to find out how to reference them in the "app" so that when I call manage.py sql app it generates my model.
As long as you're hooked up to the database in question in your settings file, and the model defines fields that exist on the table, you just need to set the db_table
meta option to refer to the actual table name and the SQL generated via the ORM should return results / attempt to update the table.
http://docs.djangoproject.com/en/dev/ref/models/options/#db-table
Then, it's just a matter of importing that model and using the ORM. As Ignacio linked to, you will have to specify os.environ['DJANGO_SETTINGS_MODULE']
for django to know which settings file to use for your model.
PS: Awesome stuff in that post, I didn't know there was an shortcut for setting up the environment!
精彩评论