On Jan 26, 2008 8:11 AM, Chris <[EMAIL PROTECTED]> wrote: > > Hello, > > I am seeking to do something like this: > > def dynamic_model_call(model_name): > test = model_name.objects.all() > return test >
This will work fine as long as you pass an actual model into the method: >>> dynamic_model_call(Author) If you want to be able to invoke something like: >>> dynamic_model_call("Author") (i.e., use the string version of the model name), all you need to do use use the get_model() method that is part of the Django model loader: def dynamic_model_call(model_name): model = get_model(*(model_name.split('.'))) return model.objects.all() get_model takes two arguments - the application name and the model name, so you will need to use a model name of "auth.User", not just "User" >>> dynamic_model_call('auth.User') Alternatively, you could provide two arguments to dynamic_model_call (app_name and model_name), or you could hard code the app_name into the method. Yours, Russ Magee %-) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---