基于现有数据库表创建动态Django模型 [英] Dynamic Django model creation based on existing DB table

查看:230
本文介绍了基于现有数据库表创建动态Django模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如何使用type()模块来动态创建一个基于现有数据库表的Django模型,而无需手动写入或使用manage.py生成器检查数据库。原因是我的模式频繁变化 - 添加新表,添加/删除列等。任何人都有一个很好的解决方案?与此类似的事情将会非常棒: http:// www .b-list.org / weblog / 2008 / nov / 09 / dynamic-forms /

解决方案

请查看 inspectdb code ,以及而不是输出代码返回类。


I'm trying to figure out how I can use the type() module to dynamically create a Django model based on existing DB tables without having to either write it out manually or use the manage.py generator to inspect the DB. Reason is my schema changes frequently -- adding new tables, adding/deleting columns, etc. Anyone have a good solution? Something similar to this would be awesome: http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/

解决方案

You can look at inspectdb code, and instead of outputting code return classes.

这篇关于基于现有数据库表创建动态Django模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆