Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
coercing to Unicode: need string or buffer, Connector found
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
adelaide_mike  
View profile  
 More options Nov 4, 7:10 pm
From: adelaide_mike <mike.ro...@internode.on.net>
Date: Wed, 4 Nov 2009 16:10:51 -0800 (PST)
Local: Wed, Nov 4 2009 7:10 pm
Subject: coercing to Unicode: need string or buffer, Connector found
Hi.  Still learning, slowly.  This is Django 1.0.2
The relevant models are Unit, Connector and Cable

class Cable(models.Model):
    cable = models.CharField(max_length=8, blank=False)
    desc = models.CharField(max_length=128, blank=True)
    cabletype = models.ForeignKey(Cabletype, blank=True, null=True)
    connector_left = models.ForeignKey(Connector,
related_name='cable_left', blank=True, null=True)
    connector_right = models.ForeignKey(Connector,
related_name='cable_right', blank=True, null=True)
    length = models.DecimalField
(max_digits=8,decimal_places=2,blank=True,null=True)
    version = models.ForeignKey(Version, blank=True, null=True)
    def __unicode__(self):
        return '%s:%s' % (self.cable, self.version)
    class Meta:
        ordering = ['cable']
        unique_together=('cable','version')

class Unit(models.Model):
    unit = models.CharField(max_length=8, blank=False)
    desc = models.CharField(max_length=128, blank=True)
    rack = models.ForeignKey(Rack)
    version = models.ForeignKey(Version, blank=True, null=True)
    def __unicode__(self):
        return '%s-%s' % (unicode(self.rack), self.unit)
    class Meta:
        ordering = ['rack','unit']
        unique_together=('rack','unit')

class Connector(models.Model):
    connector = models.CharField(max_length=8, blank=False)
    desc = models.CharField(max_length=128, blank=True)
    unit = models.ForeignKey(Unit)
    connectortype = models.ForeignKey(Connectortype, blank=True,
null=True)
    def __unicode__(self):
        return '%s-%s' % (unicode(self.unit), self.connector)
    class Meta:
        ordering = ['unit','connector']
        unique_together=('unit','connector')

Attempting my first reportlab report I get this TypeError:

 coercing to Unicode: need string or buffer, Connector found

at the last line in the following view (very much a prototype)

<snip>
    cables = Cable.objects.all()
    for cable in cables:
        print "cable=",
cable                                                # prints OK
        print "connector_left=", cable.connector_left
#prints OK
        p = Paragraph(cable.cable+cable.desc+cable.connector_left,
style)

If I make the last line:
p = Paragrapg(cable.cable+cable.desc,style)

the report is generated correctly.

What does the TypeError want me to change?

Thanks

Mike


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Karen Tracey  
View profile  
 More options Nov 5, 12:21 am
From: Karen Tracey <kmtra...@gmail.com>
Date: Thu, 5 Nov 2009 00:21:52 -0500
Local: Thurs, Nov 5 2009 12:21 am
Subject: Re: coercing to Unicode: need string or buffer, Connector found

On Wed, Nov 4, 2009 at 7:10 PM, adelaide_mike
<mike.ro...@internode.on.net>wrote:

It wants you to not try to concatenate a Connector with a unicode type.

You've got:

<type 'unicode'>+<type 'unicode'>+<class 'Connector'>

You can either do:

cable.cable+cable.desc+unicode(cable.connector_left)

or:

'%s%s%s" % (cable.cable, cable.desc, cable.connector_left)

When you use + to concatenate string/unicode objects the operands must be of
an appropriate type or they must be something that can be coerced to the
right type.  Having a __unicode__ method doesn't allow something to be
coerced to unicode, it just implements the unicode representation for the
instances of the class.

Karen


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google