开发者

How do I use a variable as table name in Django?

I'd like t开发者_高级运维o do the following:

for table in table_list:
   'table'.samefield = newvalue


If you know the name of the application that it's in, then you can do

model = getattr(application_name.models, 'table')
model.somefield = newvalue

or just

getattr(application_name.models, 'table').somefield = newvalue

if you only want to access it once (although that doesn't really make any sense).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜