On Tue, 2008-12-09 at 19:23 -0800, DragonSlayre wrote: > Hi, > > I've just made a new 'Student' model, and was trying to create a new > Student in the admin interface, and I got the following error: > > Environment: > > Request Method: POST > Request URL: http://localhost:8000/admin/student/student/add/ > Django Version: 1.0.2 final > Python Version: 2.5.2 > Installed Applications: > ['django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > 'django.contrib.sites', > 'django.contrib.admin', > 'mysite.student'] > Installed Middleware: > ('django.middleware.common.CommonMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware') > > > Traceback: > File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py" > in get_response > 86. response = callback(request, *callback_args, > **callback_kwargs) > File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py" > in root > 157. return self.model_page(request, *url.split('/', > 2)) > File "/usr/lib/python2.5/site-packages/django/views/decorators/ > cache.py" in _wrapped_view_func > 44. response = view_func(request, *args, **kwargs) > File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py" > in model_page > 176. return admin_obj(request, rest_of_url) > File "/usr/lib/python2.5/site-packages/django/contrib/admin/ > options.py" in __call__ > 191. return self.add_view(request) > File "/usr/lib/python2.5/site-packages/django/db/transaction.py" in > _commit_on_success > 238. res = func(*args, **kw) > File "/usr/lib/python2.5/site-packages/django/contrib/admin/ > options.py" in add_view > 499. self.log_addition(request, new_object) > File "/usr/lib/python2.5/site-packages/django/contrib/admin/ > options.py" in log_addition > 294. object_repr = force_unicode(object), > File "/usr/lib/python2.5/site-packages/django/utils/encoding.py" in > force_unicode > 49. s = unicode(s) > > Exception Type: TypeError at /admin/student/student/add/ > Exception Value: coercing to Unicode: need string or buffer, tuple > found > > > > > My model looks like this:
> class Student(models.Model): [...] > def __unicode__(self): > return self.user.username, ", ", self.user.first_name, " ", > self.user.last_name You are returning a tuple here and you must return a unicode object. If you want to concatenate strings, do it with "+", or use format markers like so: return u"%s, %s %s" % (self.user.username, self.user.first_name, self.user.last_name) Using commas to separate objects, even without the surrounding parentheses, is how you specify a tuple in Python. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---