2010/3/5 Omer Barlas <omer.bar...@gmail.com> > I have an ajax form which updates the status field of a table's status > column dynamically. I send the table name, and the Id to be replaced to the > ajax processor, but when I try to call > > what = model_name.objects.get(Id=id_number) > > django barks at me like this; > > Traceback: > File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in > get_response > 92. response = callback(request, *callback_args, > **callback_kwargs) > File "/home/www/django/adm/ajax/views.py" in statusUpdate > 15. what = model_name.objects.get(Id=id_number) > > Exception Type: AttributeError at /adm/ajax/statusUpdate/ > Exception Value: 'unicode' object has no attribute 'objects' > > How can I use a unicode string as a model instance? > >
AFAIK you can't, but you can retrieve a model class object from the model name using from django.db.models import get_model model_class = get_model('appname', model_name) # appname is the application name what = model_class.objects.get(Id=id_number) Hope this helps. -- Alessandro Pasotti w3: www.itopen.it -- 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.