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).
精彩评论