开发者

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

开发者 https://www.devze.com 2023-01-21 19:12 出处:网络
I\'d like t开发者_高级运维o do the following: for table in table_list: \'table\'.samefield = newvalue

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

精彩评论

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