#4796: force_unicode error
--------------------------------------+-------------------------------------
   Reporter:  [EMAIL PROTECTED]      |                Owner:  mtredinnick   
     Status:  new                     |            Component:  Core framework
    Version:                          |           Resolution:                
   Keywords:  fcgi unicode __proxy__  |                Stage:  Accepted      
  Has_patch:  0                       |           Needs_docs:  0             
Needs_tests:  0                       |   Needs_better_patch:  0             
--------------------------------------+-------------------------------------
Comment (by [EMAIL PROTECTED]):

 I'm having what I believe to be at least a related issue, using SVN r5993.
 The patch doesn't help at all, and the bt remains the same.
 
 Here's my models:
 {{{
 class ExtendedUser(models.Model):
     user = models.ForeignKey(User)
     first_name = models.CharField(_("First name"), maxlength=128)
     surname = models.CharField(_("Surname"), maxlength=128)
     surname_first = models.BooleanField(_("Surname first"), default=False)
     url = models.URLField(_("URL"), blank=True, null=True)
     confirmation_string = models.CharField(_("Email validation string"),
                                            maxlength=32, blank=True,
 null=True)
 
     # The user's identifier is their name.
     def __unicode__(self):
         if self.surname_first:
             return "%s %s" % (self.surname, self.first_name)
         else:
             return "%s %s" % (self.first_name, self.surname)
 
     # Allow administration, with all the defaults.
     class Admin:
         pass
 
 class Attendee(models.Model):
     user = models.ForeignKey(ExtendedUser)
     [...]
 }}}
 
 Running the following code from a view:
 {{{
 def detail(request, attendee_id):
     if not request.user.is_anonymous():
         user = ExtendedUser.objects.get(user=request.user)
     else:
         user = None
     print "%s" % user
 
     attendee = get_object_or_404(Attendee, id=attendee_id)
     print "%s" % attendee.user
     print "%s" % attendee
 }}}
 
 Will print 'Daniel Stone' twice (with the first and second prints), but
 tank with the following backtrace on the third:
 {{{
 Traceback (most recent call last):
 File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py" in
 get_response
   77. response = callback(request, *callback_args, **callback_kwargs)
 File
 
"/home/daniels/x/xds/site/endtroducing/../endtroducing/xds2007/attendees/views.py"
 in detail
   47. print "%s" % attendee
 File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in
 __str__
   91. return force_unicode(self).encode('utf-8')
 File "/usr/lib/python2.5/site-packages/django/utils/encoding.py" in
 force_unicode
   37. s = unicode(s)
 
   TypeError at /xds2007/attendees/1/
   coercing to Unicode: need string or buffer, ExtendedUser found
 }}}
 
 Hope that helps.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/4796#comment:19>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to