从Django中的现有数据库生成一些模型

col*_*ebb 4 django django-models django-database

我知道这存在

django-admin.py inspectdb > models.py
Run Code Online (Sandbox Code Playgroud)

但是,是否有一种简单的方法来限制它?没有手动删除我不想要的东西.

我正在连接到一个有超过一百个表的数据库,但我只想要大约4或5的模型.是否有一种简单的方法从几个给定的表生成模型?

它们是相当大的桌子,所以我也不想把它们全部输入.

pfc*_*ise 7

我自己也是这样做的,也是Oracle的.这是可能的 - 但不是很漂亮.

假设您知道所需表格的名称 -

打开django/db/backends/oracle/introspection.py.有一个功能get_table_list:

def get_table_list(self, cursor):
    "Returns a list of table names in the current database."
    cursor.execute("SELECT TABLE_NAME FROM USER_TABLES")
    return [row[0].lower() for row in cursor.fetchall()]
Run Code Online (Sandbox Code Playgroud)

只需用类似的东西替换它

def get_table_list(self, cursor):
    names = ['mytable1', 'mytable2', 'mytable3']
    return names
Run Code Online (Sandbox Code Playgroud)

然后运行你的inspectdb,它将更加可管理:)