Don't think it is good idea to do so. In this case dict_variables['modelname'].objects.filter(status_listurl='u') you call method objects on string. but string doesn't have such method. you should use smth like modelclass = globals()['modelname']
for example: >>> import os >>> o=globals()['os'] # or locals() depending on context >>> o <module 'os' from 'C:\Python25\lib\os.pyc'> to import by passing a string try help(__import__) On 24 August 2010 12:19, Rick <r.dane1...@gmail.com> wrote: > I'm using Django as my framework but am doing things beyond regular > web development as I have some a lot of "components" outside of any of > the django apps that I am often interacting with and, in some of > these, I want to be able to make calls to the database for a model but > want to be able to pass in the model's name as a variable since I want > to write re-usable code as much as possible... I have really been > struggling in figuring out how to do this and would appreciate any > advice.. below is some example code of what I am trying to do: > > def call_database_from_variable (dict_variables) > from web1.dict_variables['appname'].models import > dict_variables['modelname'] > p = > dict_variables['modelname'].objects.filter(status_listurl='u') > > > dict_variables={'app':'myappname','model':'Mymodelname','field':'field_i_want_to_get'} > call_database_from_variable (dict_variables) > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- Best Regards, Mila -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.