Domanda

I have a ForeignKeyField in model number one that displays a __unicode__self.name.

I want to use the same unicode in the second model, but everytime I try to do that it's says I need to encode it, I've been trying to solve this by reading Django docs but I can't figure out how.

Here's the code:

class Viaje(models.Model):
    cliente = models.ForeignKey(Cliente)
    fecha = models.CharField(max_length=244, blank=True)
    origen = models.CharField(max_length=244, blank=True)
    destino = models.CharField(max_length=244, blank=True)
    tracto_numero = models.CharField(max_length=244, blank=True)



    def __unicode__(self):
        return self.cliente
È stato utile?

Soluzione

Try this:

def __unicode__(self):
    return unicode(self.cliente)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top